From 55626f96ccaab76191161b68b3101265ccf9d96e Mon Sep 17 00:00:00 2001 From: Jon Shallow Date: Wed, 26 Jul 2023 12:10:59 +0000 Subject: [PATCH] UPdate --- .gitmodules | 2 +- coap/CMakeLists.txt | 9 ++ coap/Kconfig | 14 +-- coap/examples/coap_client/README.md | 4 +- .../coap_client/main/Kconfig.projbuild | 6 - .../main/coap_client_example_main.c | 111 ++++++---------- coap/examples/coap_client/sdkconfig.ci | 3 + .../coap_server/main/Kconfig.projbuild | 37 +++++- .../main/coap_server_example_main.c | 118 ++++++++++-------- coap/examples/coap_server/sdkconfig.ci | 11 ++ coap/libcoap | 2 +- 11 files changed, 167 insertions(+), 150 deletions(-) create mode 100644 coap/examples/coap_server/sdkconfig.ci diff --git a/.gitmodules b/.gitmodules index 60ac5ab00d..2277659038 100644 --- a/.gitmodules +++ b/.gitmodules @@ -48,7 +48,7 @@ [submodule "coap/libcoap"] path = coap/libcoap url = https://github.com/obgm/libcoap.git - sbom-version = 4.3.1 + sbom-version = 4.3.2 sbom-cpe = cpe:2.3:a:libcoap:libcoap:{}:*:*:*:*:*:*:* sbom-supplier = Organization: libcoap sbom-url = https://github.com/obgm/libcoap diff --git a/coap/CMakeLists.txt b/coap/CMakeLists.txt index bc9910a0d6..f5fae695cb 100644 --- a/coap/CMakeLists.txt +++ b/coap/CMakeLists.txt @@ -31,6 +31,15 @@ set(srcs "libcoap/src/coap_uri.c" "libcoap/src/coap_ws.c") +if(CONFIG_COAP_OSCORE_SUPPORT) + list(APPEND srcs + "libcoap/src/oscore/oscore.c" + "libcoap/src/oscore/oscore_cbor.c" + "libcoap/src/oscore/oscore_context.c" + "libcoap/src/oscore/oscore_cose.c" + "libcoap/src/oscore/oscore_crypto.c") +endif() + idf_component_register(SRCS "${srcs}" INCLUDE_DIRS "${include_dirs}" REQUIRES lwip mbedtls) diff --git a/coap/Kconfig b/coap/Kconfig index f4276b5f48..548b456c2d 100644 --- a/coap/Kconfig +++ b/coap/Kconfig @@ -80,15 +80,15 @@ menu "CoAP Configuration" Enable TCP functionality for CoAP. This is required if TLS sessions are to be used. - If this option is disabled, redundent CoAP TCP code is removed. + If this option is disabled, redundant CoAP TCP code is removed. config COAP_OSCORE_SUPPORT bool "Enable OSCORE support within CoAP" default n help - Enable OSCORE functionality for CoAP. + Enable OSCORE (Object Security for Constrained RESTful Environments) functionality for CoAP. - If this option is disabled, redundent CoAP OSCORE code is removed. + If this option is disabled, redundant CoAP OSCORE code is removed. config COAP_OBSERVE_PERSIST bool "Enable Server Observe Persist support within CoAP" @@ -96,7 +96,7 @@ menu "CoAP Configuration" help Enable Server Observe Persist support for CoAP. - If this option is disabled, redundent CoAP Observe Persist code is removed. + If this option is disabled, redundant CoAP Observe Persist code is removed. config COAP_WEBSOCKETS bool "Enable WebSockets support within CoAP" @@ -104,7 +104,7 @@ menu "CoAP Configuration" help Enable WebSockets support for CoAP. - If this option is disabled, redundent CoAP WebSocket code is removed. + If this option is disabled, redundant CoAP WebSocket code is removed. config COAP_CLIENT_SUPPORT bool "Enable Client functionality within CoAP" @@ -115,7 +115,7 @@ menu "CoAP Configuration" this needs to be enabled to support the ongoing session going to the next hop. - If this option is disabled, redundent CoAP client only code is removed. + If this option is disabled, redundant CoAP client only code is removed. If both this option and COAP_SERVER_SUPPORT are disabled, then both are automatically enabled for backwards compatability. @@ -126,7 +126,7 @@ menu "CoAP Configuration" Enable server functionality (ability to receive requests and send responses) for CoAP. - If this option is disabled, redundent CoAP server only code is removed. + If this option is disabled, redundant CoAP server only code is removed. If both this option and COAP_CLIENT_SUPPORT are disabled, then both are automatically enabled for backwards compatability. diff --git a/coap/examples/coap_client/README.md b/coap/examples/coap_client/README.md index ea19836d9f..1ed3e2f969 100644 --- a/coap/examples/coap_client/README.md +++ b/coap/examples/coap_client/README.md @@ -101,8 +101,10 @@ These can be raised at [libcoap Issues](https://github.com/obgm/libcoap/issues). ## Troubleshooting * Please make sure Target Url includes valid `host`, optional `port`, -optional `path`, and begins with `coap://`, `coaps://`, `coap+tcp://` or `coaps+tcp://` +optional `path`, and begins with `coap://`, `coaps://`, `coap+tcp://`, `coaps+tcp://`, +coap+ws:// or coaps+ws://. (not all hosts support TCP/TLS including coap+tcp://californium.eclipseprojects.io). +(not all hosts support WebSockets (which needs to be enabled as an option). * 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 diff --git a/coap/examples/coap_client/main/Kconfig.projbuild b/coap/examples/coap_client/main/Kconfig.projbuild index add9065972..206b2fa712 100644 --- a/coap/examples/coap_client/main/Kconfig.projbuild +++ b/coap/examples/coap_client/main/Kconfig.projbuild @@ -1,11 +1,5 @@ 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" diff --git a/coap/examples/coap_client/main/coap_client_example_main.c b/coap/examples/coap_client/main/coap_client_example_main.c index 39e5f8a859..e008c4c5fb 100644 --- a/coap/examples/coap_client/main/coap_client_example_main.c +++ b/coap/examples/coap_client/main/coap_client_example_main.c @@ -89,7 +89,7 @@ static int wait_ms; as the Certificate test (by default) is against the californium server. To embed it in the app binary, the PEM, CRT and KEY file is named - in the component.mk COMPONENT_EMBED_TXTFILES variable. + in the CMakeLists.txt EMBED_TXTFILES definition. */ extern uint8_t ca_pem_start[] asm("_binary_coap_ca_pem_start"); extern uint8_t ca_pem_end[] asm("_binary_coap_ca_pem_end"); @@ -156,69 +156,16 @@ static void coap_log_handler (coap_log_t level, const char *message) { uint32_t esp_level = ESP_LOG_INFO; - char *cp = strchr(message, '\n'); + const char *cp = strchr(message, '\n'); - if (cp) { + while (cp) { ESP_LOG_LEVEL(esp_level, TAG, "%.*s", (int)(cp - message), message); - } else { - ESP_LOG_LEVEL(esp_level, TAG, "%s", message); - } -} - -static coap_address_t * -coap_get_address(coap_uri_t *uri) -{ - static coap_address_t dst_addr; - char *phostname = NULL; - struct addrinfo hints; - struct addrinfo *addrres; - int error; - char tmpbuf[INET6_ADDRSTRLEN]; - - phostname = (char *)calloc(1, uri->host.length + 1); - if (phostname == NULL) { - ESP_LOGE(TAG, "calloc failed"); - return NULL; - } - memcpy(phostname, uri->host.s, uri->host.length); - - memset ((char *)&hints, 0, sizeof(hints)); - hints.ai_socktype = SOCK_DGRAM; - hints.ai_family = AF_UNSPEC; - - error = getaddrinfo(phostname, NULL, &hints, &addrres); - if (error != 0) { - ESP_LOGE(TAG, "DNS lookup failed for destination address %s. error: %d", phostname, error); - free(phostname); - return NULL; + message = cp + 1; + cp = strchr(message, '\n'); } - if (addrres == NULL) { - ESP_LOGE(TAG, "DNS lookup %s did not return any addresses", phostname); - free(phostname); - return NULL; - } - free(phostname); - coap_address_init(&dst_addr); - switch (addrres->ai_family) { - case AF_INET: - memcpy(&dst_addr.addr.sin, addrres->ai_addr, sizeof(dst_addr.addr.sin)); - dst_addr.addr.sin.sin_port = htons(uri->port); - inet_ntop(AF_INET, &dst_addr.addr.sin.sin_addr, tmpbuf, sizeof(tmpbuf)); - ESP_LOGI(TAG, "DNS lookup succeeded. IP=%s", tmpbuf); - break; - case AF_INET6: - memcpy(&dst_addr.addr.sin6, addrres->ai_addr, sizeof(dst_addr.addr.sin6)); - dst_addr.addr.sin6.sin6_port = htons(uri->port); - inet_ntop(AF_INET6, &dst_addr.addr.sin6.sin6_addr, tmpbuf, sizeof(tmpbuf)); - ESP_LOGI(TAG, "DNS lookup succeeded. IP=%s", tmpbuf); - break; - default: - ESP_LOGE(TAG, "DNS lookup response failed"); - return NULL; + if (message[0] != '\000') { + ESP_LOG_LEVEL(esp_level, TAG, "%s", message); } - freeaddrinfo(addrres); - - return &dst_addr; } static int @@ -278,7 +225,7 @@ coap_build_optlist(coap_uri_t *uri) } #ifdef CONFIG_COAP_MBEDTLS_PSK static coap_session_t * -coap_start_psk_session(coap_context_t *ctx, coap_address_t *dst_addr, coap_uri_t *uri) +coap_start_psk_session(coap_context_t *ctx, coap_address_t *dst_addr, coap_uri_t *uri, coap_proto_t proto) { static coap_dtls_cpsk_t dtls_psk; static char client_sni[256]; @@ -298,15 +245,14 @@ coap_start_psk_session(coap_context_t *ctx, coap_address_t *dst_addr, coap_uri_t dtls_psk.psk_info.identity.length = sizeof(EXAMPLE_COAP_PSK_IDENTITY) - 1; dtls_psk.psk_info.key.s = (const uint8_t *)EXAMPLE_COAP_PSK_KEY; dtls_psk.psk_info.key.length = sizeof(EXAMPLE_COAP_PSK_KEY) - 1; - return coap_new_client_session_psk2(ctx, NULL, dst_addr, - uri->scheme == COAP_URI_SCHEME_COAPS ? COAP_PROTO_DTLS : COAP_PROTO_TLS, + return coap_new_client_session_psk2(ctx, NULL, dst_addr, proto, &dtls_psk); } #endif /* CONFIG_COAP_MBEDTLS_PSK */ #ifdef CONFIG_COAP_MBEDTLS_PKI static coap_session_t * -coap_start_pki_session(coap_context_t *ctx, coap_address_t *dst_addr, coap_uri_t *uri) +coap_start_pki_session(coap_context_t *ctx, coap_address_t *dst_addr, coap_uri_t *uri, coap_proto_t proto) { unsigned int ca_pem_bytes = ca_pem_end - ca_pem_start; unsigned int client_crt_bytes = client_crt_end - client_crt_start; @@ -357,15 +303,14 @@ coap_start_pki_session(coap_context_t *ctx, coap_address_t *dst_addr, coap_uri_t dtls_pki.pki_key.key.pem_buf.ca_cert = ca_pem_start; dtls_pki.pki_key.key.pem_buf.ca_cert_len = ca_pem_bytes; - return coap_new_client_session_pki(ctx, NULL, dst_addr, - uri->scheme == COAP_URI_SCHEME_COAPS ? COAP_PROTO_DTLS : COAP_PROTO_TLS, + return coap_new_client_session_pki(ctx, NULL, dst_addr, proto, &dtls_pki); } #endif /* CONFIG_COAP_MBEDTLS_PKI */ static void coap_example_client(void *p) { - coap_address_t *dst_addr; + coap_address_t dst_addr; static coap_uri_t uri; const char *server_uri = COAP_DEFAULT_DEMO_URI; coap_context_t *ctx = NULL; @@ -373,6 +318,8 @@ static void coap_example_client(void *p) coap_pdu_t *request = NULL; unsigned char token[8]; size_t tokenlength; + coap_addr_info_t *info_list = NULL; + coap_proto_t proto; /* Initialize libcoap library */ coap_startup(); @@ -400,40 +347,52 @@ static void coap_example_client(void *p) goto clean_up; } - dst_addr = coap_get_address(&uri); - if (!dst_addr) { + info_list = coap_resolve_address_info(&uri.host, uri.port, uri.port, + uri.port, uri.port, + 0, + 1 << uri.scheme, + COAP_RESOLVE_TYPE_REMOTE); + + if (info_list == NULL) { + ESP_LOGE(TAG, "failed to resolve address"); goto clean_up; } + proto = info_list->proto; + memcpy(&dst_addr, &info_list->addr, sizeof(dst_addr)); + coap_free_address_info(info_list); /* * Note that if the URI starts with just coap:// (not coaps://) the * session will still be plain text. */ - if (uri.scheme == COAP_URI_SCHEME_COAPS || uri.scheme == COAP_URI_SCHEME_COAPS_TCP) { + if (uri.scheme == COAP_URI_SCHEME_COAPS || uri.scheme == COAP_URI_SCHEME_COAPS_TCP || uri.scheme == COAP_URI_SCHEME_COAPS_WS) { #ifndef CONFIG_MBEDTLS_TLS_CLIENT ESP_LOGE(TAG, "MbedTLS (D)TLS Client Mode not configured"); goto clean_up; #endif /* CONFIG_MBEDTLS_TLS_CLIENT */ #ifdef CONFIG_COAP_MBEDTLS_PSK - session = coap_start_psk_session(ctx, dst_addr, &uri); + session = coap_start_psk_session(ctx, &dst_addr, &uri, proto); #endif /* CONFIG_COAP_MBEDTLS_PSK */ #ifdef CONFIG_COAP_MBEDTLS_PKI - session = coap_start_pki_session(ctx, dst_addr, &uri); + session = coap_start_pki_session(ctx, &dst_addr, &uri, proto); #endif /* CONFIG_COAP_MBEDTLS_PKI */ } else { - session = coap_new_client_session(ctx, NULL, dst_addr, - uri.scheme == COAP_URI_SCHEME_COAP_TCP ? COAP_PROTO_TCP : - COAP_PROTO_UDP); + session = coap_new_client_session(ctx, NULL, &dst_addr, proto); } if (!session) { ESP_LOGE(TAG, "coap_new_client_session() failed"); goto clean_up; } +#ifdef CONFIG_COAP_WEBSOCKETS + if (proto == COAP_PROTO_WS || proto == COAP_PROTO_WSS) { + coap_ws_set_host_request(session, &uri.host); + } +#endif /* CONFIG_COAP_WEBSOCKETS */ while (1) { - request = coap_new_pdu(coap_is_mcast(dst_addr) ? COAP_MESSAGE_NON : COAP_MESSAGE_CON, + request = coap_new_pdu(coap_is_mcast(&dst_addr) ? COAP_MESSAGE_NON : COAP_MESSAGE_CON, COAP_REQUEST_CODE_GET, session); if (!request) { ESP_LOGE(TAG, "coap_new_pdu() failed"); diff --git a/coap/examples/coap_client/sdkconfig.ci b/coap/examples/coap_client/sdkconfig.ci index f958eb22e9..ca4b9a2c09 100644 --- a/coap/examples/coap_client/sdkconfig.ci +++ b/coap/examples/coap_client/sdkconfig.ci @@ -6,3 +6,6 @@ CONFIG_EXAMPLE_ETH_MDC_GPIO=23 CONFIG_EXAMPLE_ETH_MDIO_GPIO=18 CONFIG_EXAMPLE_ETH_PHY_RST_GPIO=5 CONFIG_EXAMPLE_ETH_PHY_ADDR=1 +CONFIG_COAP_OSCORE_SUPPORT=y +CONFIG_COAP_OBSERVE_PERSIST=y +CONFIG_COAP_WEBSOCKETS=y diff --git a/coap/examples/coap_server/main/Kconfig.projbuild b/coap/examples/coap_server/main/Kconfig.projbuild index 92ee399376..6feee73258 100644 --- a/coap/examples/coap_server/main/Kconfig.projbuild +++ b/coap/examples/coap_server/main/Kconfig.projbuild @@ -1,11 +1,5 @@ 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 @@ -15,6 +9,37 @@ menu "Example CoAP Server Configuration" used at both ends of the CoAP connection, and the CoaP client must request an URI prefixed with coaps:// instead of coap:// for DTLS to be used. + config EXAMPLE_COAP_LISTEN_PORT + string "CoAP Listen port" + default "5683" + help + Port number to listen for CoAP traffic. + + config EXAMPLE_COAPS_LISTEN_PORT + string "CoAP Secure Listen port" + default "5684" + depends on COAP_MBEDTLS_PSK || COAP_MBEDTLS_PKI + help + Port number to listen for CoAP secure ((D)TLS) traffic. + + config EXAMPLE_COAP_WEBSOCKET_PORT + string "CoAP Websocket port" + default "80" + depends on COAP_WEBSOCKETS + help + Port number to listen for WebSocket traffic on. + + The default is 80. + + config EXAMPLE_COAP_WEBSOCKET_SECURE_PORT + string "CoAP Websocket Secure port" + default "443" + depends on COAP_WEBSOCKETS && (COAP_MBEDTLS_PSK || COAP_MBEDTLS_PKI) + help + Port number to listen for WebSocket Secure (TLS) traffic on. + + The default is 443. + choice EXAMPLE_COAP_MCAST_IP_MODE prompt "Receive Multicast IP type" help diff --git a/coap/examples/coap_server/main/coap_server_example_main.c b/coap/examples/coap_server/main/coap_server_example_main.c index 1e7bdefc19..1ccad2e329 100644 --- a/coap/examples/coap_server/main/coap_server_example_main.c +++ b/coap/examples/coap_server/main/coap_server_example_main.c @@ -75,7 +75,7 @@ static int espressif_data_len = 0; californium server. To embed it in the app binary, the PEM, CRT and KEY file is named - in the component.mk COMPONENT_EMBED_TXTFILES variable. + in the CMakeLists.txt EMBED_TXTFILES definition. */ extern uint8_t ca_pem_start[] asm("_binary_coap_ca_pem_start"); extern uint8_t ca_pem_end[] asm("_binary_coap_ca_pem_end"); @@ -172,11 +172,14 @@ static void coap_log_handler (coap_log_t level, const char *message) { uint32_t esp_level = ESP_LOG_INFO; - char *cp = strchr(message, '\n'); + const char *cp = strchr(message, '\n'); - if (cp) { + while (cp) { ESP_LOG_LEVEL(esp_level, TAG, "%.*s", (int)(cp - message), message); - } else { + message = cp + 1; + cp = strchr(message, '\n'); + } + if (message[0] != '\000') { ESP_LOG_LEVEL(esp_level, TAG, "%s", message); } } @@ -184,8 +187,27 @@ coap_log_handler (coap_log_t level, const char *message) static void coap_example_server(void *p) { coap_context_t *ctx = NULL; - coap_address_t serv_addr; coap_resource_t *resource = NULL; + int have_ep = 0; + uint16_t u_s_port = atoi(CONFIG_EXAMPLE_COAP_LISTEN_PORT); +#ifdef CONFIG_EXAMPLE_COAPS_LISTEN_PORT + uint16_t s_port = atoi(CONFIG_EXAMPLE_COAPS_LISTEN_PORT); +#else /* ! CONFIG_EXAMPLE_COAPS_LISTEN_PORT */ + uint16_t s_port = 0; +#endif /* ! CONFIG_EXAMPLE_COAPS_LISTEN_PORT */ + +#ifdef CONFIG_EXAMPLE_COAP_WEBSOCKET_PORT + uint16_t ws_port = atoi(CONFIG_EXAMPLE_COAP_WEBSOCKET_PORT); +#else /* ! CONFIG_EXAMPLE_COAP_WEBSOCKET_PORT */ + uint16_t ws_port = 0; +#endif /* ! CONFIG_EXAMPLE_COAP_WEBSOCKET_PORT */ + +#ifdef CONFIG_EXAMPLE_COAP_WEBSOCKET_SECURE_PORT + uint16_t ws_s_port = atoi(CONFIG_EXAMPLE_COAP_WEBSOCKET_SECURE_PORT); +#else /* ! CONFIG_EXAMPLE_COAP_WEBSOCKET_SECURE_PORT */ + uint16_t ws_s_port = 0; +#endif /* ! CONFIG_EXAMPLE_COAP_WEBSOCKET_SECURE_PORT */ + uint32_t scheme_hint_bits; /* Initialize libcoap library */ coap_startup(); @@ -196,22 +218,18 @@ static void coap_example_server(void *p) coap_set_log_level(EXAMPLE_COAP_LOG_DEFAULT_LEVEL); while (1) { - coap_endpoint_t *ep = NULL; unsigned wait_ms; - int have_dtls = 0; - - /* Prepare the CoAP server socket */ - coap_address_init(&serv_addr); - serv_addr.addr.sin6.sin6_family = AF_INET6; - serv_addr.addr.sin6.sin6_port = htons(COAP_DEFAULT_PORT); + coap_addr_info_t *info = NULL; + coap_addr_info_t *info_list = NULL; ctx = coap_new_context(NULL); if (!ctx) { ESP_LOGE(TAG, "coap_new_context() failed"); - continue; + goto clean_up; } coap_context_set_block_mode(ctx, COAP_BLOCK_USE_LIBCOAP | COAP_BLOCK_SINGLE_BODY); + #ifdef CONFIG_COAP_MBEDTLS_PSK /* Need PSK setup before we set up endpoints */ coap_context_set_psk(ctx, "CoAP", @@ -265,51 +283,47 @@ static void coap_example_server(void *p) coap_context_set_pki(ctx, &dtls_pki); #endif /* CONFIG_COAP_MBEDTLS_PKI */ - ep = coap_new_endpoint(ctx, &serv_addr, COAP_PROTO_UDP); - if (!ep) { - ESP_LOGE(TAG, "udp: coap_new_endpoint() failed"); - goto clean_up; - } - if (coap_tcp_is_supported()) { - ep = coap_new_endpoint(ctx, &serv_addr, COAP_PROTO_TCP); - if (!ep) { - ESP_LOGE(TAG, "tcp: coap_new_endpoint() failed"); - goto clean_up; - } - } + /* set up the CoAP server socket(s) */ + scheme_hint_bits = + coap_get_available_scheme_hint_bits( #if defined(CONFIG_COAP_MBEDTLS_PSK) || defined(CONFIG_COAP_MBEDTLS_PKI) - if (coap_dtls_is_supported()) { -#ifndef CONFIG_MBEDTLS_TLS_SERVER - /* This is not critical as unencrypted support is still available */ - ESP_LOGI(TAG, "MbedTLS DTLS Server Mode not configured"); -#else /* CONFIG_MBEDTLS_TLS_SERVER */ - serv_addr.addr.sin6.sin6_port = htons(COAPS_DEFAULT_PORT); - ep = coap_new_endpoint(ctx, &serv_addr, COAP_PROTO_DTLS); - if (!ep) { - ESP_LOGE(TAG, "dtls: coap_new_endpoint() failed"); - goto clean_up; - } - have_dtls = 1; -#endif /* CONFIG_MBEDTLS_TLS_SERVER */ + 1, +#else /* ! CONFIG_COAP_MBEDTLS_PSK) && ! CONFIG_COAP_MBEDTLS_PKI */ + 0, +#endif /* ! CONFIG_COAP_MBEDTLS_PSK) && ! CONFIG_COAP_MBEDTLS_PKI */ +#ifdef CONFIG_COAP_WEBSOCKETS + 1, +#else /* ! CONFIG_COAP_WEBSOCKETS */ + 0, +#endif /* ! CONFIG_COAP_WEBSOCKETS */ + 0); + + info_list = coap_resolve_address_info(coap_make_str_const("::"), u_s_port, s_port, + ws_port, ws_s_port, + 0, + scheme_hint_bits, + COAP_RESOLVE_TYPE_LOCAL); + if (info_list == NULL) { + ESP_LOGE(TAG, "coap_resolve_address_info() failed"); + goto clean_up; } - if (coap_tls_is_supported()) { -#ifndef CONFIG_MBEDTLS_TLS_SERVER - /* This is not critical as unencrypted support is still available */ - ESP_LOGI(TAG, "MbedTLS TLS Server Mode not configured"); -#else /* CONFIG_MBEDTLS_TLS_SERVER */ - serv_addr.addr.sin6.sin6_port = htons(COAPS_DEFAULT_PORT); - ep = coap_new_endpoint(ctx, &serv_addr, COAP_PROTO_TLS); + + for (info = info_list; info != NULL; info = info->next) { + coap_endpoint_t *ep; + + ep = coap_new_endpoint(ctx, &info->addr, info->proto); if (!ep) { - ESP_LOGE(TAG, "tls: coap_new_endpoint() failed"); - goto clean_up; + ESP_LOGW(TAG, "cannot create endpoint for proto %u", info->proto); + } else { + have_ep = 1; } -#endif /* CONFIG_MBEDTLS_TLS_SERVER */ } - if (!have_dtls) { - /* This is not critical as unencrypted support is still available */ - ESP_LOGI(TAG, "MbedTLS (D)TLS Server Mode not configured"); + coap_free_address_info(info_list); + if (!have_ep) { + ESP_LOGE(TAG, "No endpoints available"); + goto clean_up; } -#endif /* CONFIG_COAP_MBEDTLS_PSK || CONFIG_COAP_MBEDTLS_PKI */ + resource = coap_resource_init(coap_make_str_const("Espressif"), 0); if (!resource) { ESP_LOGE(TAG, "coap_resource_init() failed"); diff --git a/coap/examples/coap_server/sdkconfig.ci b/coap/examples/coap_server/sdkconfig.ci new file mode 100644 index 0000000000..ca4b9a2c09 --- /dev/null +++ b/coap/examples/coap_server/sdkconfig.ci @@ -0,0 +1,11 @@ +CONFIG_EXAMPLE_CONNECT_ETHERNET=y +CONFIG_EXAMPLE_CONNECT_WIFI=n +CONFIG_EXAMPLE_USE_INTERNAL_ETHERNET=y +CONFIG_EXAMPLE_ETH_PHY_IP101=y +CONFIG_EXAMPLE_ETH_MDC_GPIO=23 +CONFIG_EXAMPLE_ETH_MDIO_GPIO=18 +CONFIG_EXAMPLE_ETH_PHY_RST_GPIO=5 +CONFIG_EXAMPLE_ETH_PHY_ADDR=1 +CONFIG_COAP_OSCORE_SUPPORT=y +CONFIG_COAP_OBSERVE_PERSIST=y +CONFIG_COAP_WEBSOCKETS=y diff --git a/coap/libcoap b/coap/libcoap index c35c0783e2..3f8bb33807 160000 --- a/coap/libcoap +++ b/coap/libcoap @@ -1 +1 @@ -Subproject commit c35c0783e298de956ae6b334b768dd5de4c6b035 +Subproject commit 3f8bb33807f521e9a5bbddddb0fe002f60b78a68