lwip: Support IPv6 only mode

This commit is contained in:
David Cermak
2022-10-03 17:28:01 +02:00
parent 2c8c8bfd2d
commit 5f6cb31105
40 changed files with 336 additions and 80 deletions

View File

@@ -107,3 +107,5 @@ optional `path`, and begins with `coap://`, `coaps://`, `coap+tcp://` or `coaps+
* CoAP logging can be enabled by running 'idf.py menuconfig -> Component config -> CoAP Configuration -> Enable CoAP debugging'
and setting appropriate log level. If Mbed TLS logging is required, this needs to be configured separately under mbedTLS
Component Configuration and the CoAP logging level set to mbedTLS.
* CoAP library does not support IPv6 only configuration, so it is necessary to enable `LWIP_IPv4`

View File

@@ -1,5 +1,11 @@
menu "Example CoAP Client Configuration"
# Hidden option that selects IPv4
config EXAMPLE_COAP_NEEDS_IPV4
bool
default true
select LWIP_IPV4
config EXAMPLE_TARGET_DOMAIN_URI
string "Target Uri"
default "coaps://californium.eclipseprojects.io"

View File

@@ -92,3 +92,5 @@ fetches `/.well-known/core`
* CoAP logging can be enabled by running 'idf.py menuconfig -> Component config -> CoAP Configuration -> Enable CoAP debugging'
and setting appropriate log level. If Mbed TLS logging is required, this needs to be configured separately under mbedTLS
Component Configuration and the CoAP logging level set to mbedTLS.
* CoAP library does not support IPv6 only configuration, so it is necessary to enable `LWIP_IPv4`

View File

@@ -1,5 +1,11 @@
menu "Example CoAP Server Configuration"
# Hidden option that selects IPv4
config EXAMPLE_COAP_NEEDS_IPV4
bool
default true
select LWIP_IPV4
config EXAMPLE_COAP_PSK_KEY
string "Preshared Key (PSK) to used in the connection from the CoAP client"
depends on COAP_MBEDTLS_PSK

View File

@@ -9,6 +9,8 @@ See the `esp_local_ctrl` component documentation for details.
Before using the example, run `idf.py menuconfig` (or `idf.py menuconfig` if using CMake build system) to configure Wi-Fi or Ethernet. See "Establishing Wi-Fi or Ethernet Connection" section in [examples/protocols/README.md](../README.md) for more details.
Note, that this example in not supported for IPv6-only configuration.
## Client Side Implementation
A python test script `scripts/esp_local_ctrl.py` has been provided for as a client side application for controlling the device over the same Wi-Fi network. The script relies on a pre-generated `main/certs/rootCA.pem` to verify the server certificate. The server side private key and certificate can also be found under `main/certs`, namely `prvtkey.pem` and `cacert.pem`.

View File

@@ -0,0 +1,5 @@
CONFIG_EXAMPLE_WIFI_SSID_PWD_FROM_STDIN=y
CONFIG_EXAMPLE_CONNECT_IPV4=n
CONFIG_EXAMPLE_CONNECT_IPV6=y
CONFIG_LWIP_IPV4=n
CONFIG_LWIP_IPV6=y

View File

@@ -3,6 +3,7 @@ menu "Example Configuration"
config EXAMPLE_IPV4
bool "IPV4"
default y
depends on LWIP_IPV4
config EXAMPLE_IPV6
bool "IPV6"

View File

@@ -73,6 +73,7 @@ static void tcp_server_task(void *pvParameters)
int keepCount = KEEPALIVE_COUNT;
struct sockaddr_storage dest_addr;
#ifdef CONFIG_EXAMPLE_IPV4
if (addr_family == AF_INET) {
struct sockaddr_in *dest_addr_ip4 = (struct sockaddr_in *)&dest_addr;
dest_addr_ip4->sin_addr.s_addr = htonl(INADDR_ANY);
@@ -80,8 +81,9 @@ static void tcp_server_task(void *pvParameters)
dest_addr_ip4->sin_port = htons(PORT);
ip_protocol = IPPROTO_IP;
}
#endif
#ifdef CONFIG_EXAMPLE_IPV6
else if (addr_family == AF_INET6) {
if (addr_family == AF_INET6) {
struct sockaddr_in6 *dest_addr_ip6 = (struct sockaddr_in6 *)&dest_addr;
bzero(&dest_addr_ip6->sin6_addr.un, sizeof(dest_addr_ip6->sin6_addr.un));
dest_addr_ip6->sin6_family = AF_INET6;
@@ -138,11 +140,13 @@ static void tcp_server_task(void *pvParameters)
setsockopt(sock, IPPROTO_TCP, TCP_KEEPINTVL, &keepInterval, sizeof(int));
setsockopt(sock, IPPROTO_TCP, TCP_KEEPCNT, &keepCount, sizeof(int));
// Convert ip address to string
#ifdef CONFIG_EXAMPLE_IPV4
if (source_addr.ss_family == PF_INET) {
inet_ntoa_r(((struct sockaddr_in *)&source_addr)->sin_addr, addr_str, sizeof(addr_str) - 1);
}
#endif
#ifdef CONFIG_EXAMPLE_IPV6
else if (source_addr.ss_family == PF_INET6) {
if (source_addr.ss_family == PF_INET6) {
inet6_ntoa_r(((struct sockaddr_in6 *)&source_addr)->sin6_addr, addr_str, sizeof(addr_str) - 1);
}
#endif

View File

@@ -0,0 +1,6 @@
CONFIG_EXAMPLE_WIFI_SSID_PWD_FROM_STDIN=y
CONFIG_EXAMPLE_IPV4=n
CONFIG_EXAMPLE_IPV6=y
CONFIG_EXAMPLE_CONNECT_IPV6=y
CONFIG_LWIP_IPV4=n
CONFIG_LWIP_IPV6=y