Skip to content

Commit 765c417

Browse files
committed
drivers/esp-hosted: Add IPv6 support to network interface.
Add IPv6 support by: - Including lwip/ethip6.h header when LWIP_IPV6 is enabled - Setting output_ip6 to ethip6_output for IPv6 packet handling - Adding NETIF_FLAG_MLD6 flag for IPv6 multicast support - Creating IPv6 link-local address after interface initialization Signed-off-by: Andrew Leech <[email protected]>
1 parent ead47f7 commit 765c417

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

drivers/esp-hosted/esp_hosted_netif.c

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@
3939
#include "lwip/dns.h"
4040
#include "lwip/dhcp.h"
4141
#include "netif/etharp.h"
42+
#if LWIP_IPV6
43+
#include "lwip/ethip6.h"
44+
#endif
4245

4346
#include "shared/netutils/netutils.h"
4447
#include "shared/netutils/dhcpserver.h"
@@ -53,6 +56,10 @@ static err_t netif_struct_init(struct netif *netif) {
5356
netif->output = etharp_output;
5457
netif->mtu = ESP_FRAME_MAX_PAYLOAD;
5558
netif->flags = NETIF_FLAG_BROADCAST | NETIF_FLAG_ETHARP | NETIF_FLAG_ETHERNET | NETIF_FLAG_IGMP;
59+
#if LWIP_IPV6
60+
netif->output_ip6 = ethip6_output;
61+
netif->flags |= NETIF_FLAG_MLD6;
62+
#endif
5663
esp_hosted_wifi_get_mac(netif->name[1] - '0', netif->hwaddr);
5764
netif->hwaddr_len = sizeof(netif->hwaddr);
5865
info_printf("netif_init() netif initialized\n");
@@ -63,15 +70,27 @@ int esp_hosted_netif_init(esp_hosted_state_t *state, uint32_t itf) {
6370
struct netif *netif = &state->netif[itf];
6471

6572
ip_addr_t ipconfig[4];
73+
#if LWIP_IPV6
74+
for (int i = 0; i < 4; i++) {
75+
IP_ADDR4(&ipconfig[i], 0, 0, 0, 0);
76+
}
77+
#else
6678
ipconfig[0].addr = 0;
6779
ipconfig[1].addr = 0;
6880
ipconfig[2].addr = 0;
6981
ipconfig[3].addr = 0;
82+
#endif
7083

7184
if (itf == ESP_HOSTED_AP_IF) {
85+
#if LWIP_IPV6
86+
ip4_addr_set_u32(ip_2_ip4(&ipconfig[0]), PP_HTONL(ESP_HOSTED_AP_ADDRESS));
87+
ip4_addr_set_u32(ip_2_ip4(&ipconfig[1]), PP_HTONL(ESP_HOSTED_AP_NETMASK));
88+
ip4_addr_set_u32(ip_2_ip4(&ipconfig[2]), PP_HTONL(ESP_HOSTED_AP_GATEWAY));
89+
#else
7290
ipconfig[0].addr = PP_HTONL(ESP_HOSTED_AP_ADDRESS);
7391
ipconfig[1].addr = PP_HTONL(ESP_HOSTED_AP_NETMASK);
7492
ipconfig[2].addr = PP_HTONL(ESP_HOSTED_AP_GATEWAY);
93+
#endif
7594
}
7695

7796
netif->name[0] = 'w';
@@ -86,6 +105,10 @@ int esp_hosted_netif_init(esp_hosted_state_t *state, uint32_t itf) {
86105
netif_set_link_up(netif);
87106
dns_setserver(0, &ipconfig[3]);
88107

108+
#if LWIP_IPV6
109+
netif_create_ip6_linklocal_address(netif, 1);
110+
#endif
111+
89112
if (itf == ESP_HOSTED_STA_IF) {
90113
dhcp_set_struct(netif, &state->dhcp_client);
91114
dhcp_start(netif);

0 commit comments

Comments
 (0)