diff --git a/.github/workflows/lint_build_unit_test.yml b/.github/workflows/lint_build_unit_test.yml index 59c107849..2902c9ec1 100644 --- a/.github/workflows/lint_build_unit_test.yml +++ b/.github/workflows/lint_build_unit_test.yml @@ -75,13 +75,13 @@ jobs: - name: Build ESP-IDF golioth_basics project uses: espressif/esp-idf-ci-action@v1 with: - esp_idf_version: v5.0 + esp_idf_version: v5.1.1 target: esp32 path: 'examples/esp_idf/golioth_basics' - name: Build ESP-IDF cpp project uses: espressif/esp-idf-ci-action@v1 with: - esp_idf_version: v5.0 + esp_idf_version: v5.1.1 target: esp32 path: 'examples/esp_idf/cpp' - name: Create empty certs/keys required by certificate_auth project @@ -95,13 +95,13 @@ jobs: - name: Build ESP-IDF certificate_auth project uses: espressif/esp-idf-ci-action@v1 with: - esp_idf_version: v5.0 + esp_idf_version: v5.1.1 target: esp32 path: 'examples/esp_idf/certificate_auth' - name: Build ESP-IDF magtag_demo project uses: espressif/esp-idf-ci-action@v1 with: - esp_idf_version: v5.0 + esp_idf_version: v5.1.1 target: esp32 path: 'examples/esp_idf/magtag_demo' diff --git a/.github/workflows/test_esp32s3.yml b/.github/workflows/test_esp32s3.yml index 6fe88e931..487d408f5 100644 --- a/.github/workflows/test_esp32s3.yml +++ b/.github/workflows/test_esp32s3.yml @@ -26,7 +26,7 @@ jobs: - name: Build test project uses: espressif/esp-idf-ci-action@v1 with: - esp_idf_version: v5.0 + esp_idf_version: v5.1.1 target: esp32s3 path: 'examples/esp_idf/test' - name: Create build tarball for serial flashing @@ -49,7 +49,7 @@ jobs: - name: Rebuild test project with version 1.2.99 uses: espressif/esp-idf-ci-action@v1 with: - esp_idf_version: v5.0 + esp_idf_version: v5.1.1 target: esp32s3 path: 'examples/esp_idf/test' - name: Copy test.bin to test_new.bin diff --git a/README.md b/README.md index 01b6e67c1..0ff018edf 100644 --- a/README.md +++ b/README.md @@ -137,7 +137,7 @@ The `verify.py` script will return 0 on success (all tests pass), and non-zero o | Board | Platform | Module | Last Tested Commit | | --- | --- | --- | --- | -| ESP32-S3-DevKitC-1 | ESP-IDF (v5.0) | ESP32-S3-WROOM-1 | Every commit, CI/CD | -| ESP32-DevKitC-32E | ESP-IDF (v5.0) | ESP32-WROOM-32E | v0.7.0 (Jun 15, 2023) | -| ESP32-C3-DevKitM-1 | ESP-IDF (v5.0) | ESP32-C3-MINI-1 | v0.7.0 (Jun 15, 2023) | +| ESP32-S3-DevKitC-1 | ESP-IDF (v5.1.1) | ESP32-S3-WROOM-1 | Every commit, CI/CD | +| ESP32-DevKitC-32E | ESP-IDF (v5.1.1) | ESP32-WROOM-32E | v0.7.0 (Jun 15, 2023) | +| ESP32-C3-DevKitM-1 | ESP-IDF (v5.1.1) | ESP32-C3-MINI-1 | v0.7.0 (Jun 15, 2023) | | CY8CPROTO-062-4343W | ModusToolbox (3.0.0) | PSoCĀ® 6 CYW4343W | v0.7.0 (Jun 15, 2023) | diff --git a/examples/esp_idf/README.md b/examples/esp_idf/README.md index b9b922a08..4668bad2e 100644 --- a/examples/esp_idf/README.md +++ b/examples/esp_idf/README.md @@ -2,11 +2,11 @@ This repo contains a set of examples intended to build and run in the latest release of esp-idf -(currently [5.0](https://github.com/espressif/esp-idf/releases/tag/v5.0)). +(currently [5.1.1](https://github.com/espressif/esp-idf/releases/tag/v5.1.1)). ### Install esp-idf -Install version 5.0 of esp-idf using the +Install version 5.1.1 of esp-idf using the [installation directions from Espressif](https://docs.espressif.com/projects/esp-idf/en/latest/esp32/get-started/index.html#installation). This is the version of esp-idf this SDK is tested against. @@ -16,7 +16,7 @@ For Linux users, you can install esp-idf with these commands: sudo apt-get install git wget flex bison gperf python3 python3-venv cmake ninja-build ccache libffi-dev libssl-dev dfu-util libusb-1.0-0 mkdir -p ~/esp cd ~/esp -git clone --recursive https://github.com/espressif/esp-idf.git -b v5.0 +git clone --recursive https://github.com/espressif/esp-idf.git -b v5.1.1 cd esp-idf ./install.sh all ``` diff --git a/examples/esp_idf/certificate_auth/sdkconfig.defaults b/examples/esp_idf/certificate_auth/sdkconfig.defaults index b6000dece..9b3b7e021 100644 --- a/examples/esp_idf/certificate_auth/sdkconfig.defaults +++ b/examples/esp_idf/certificate_auth/sdkconfig.defaults @@ -8,8 +8,7 @@ CONFIG_FREERTOS_USE_TRACE_FACILITY=y CONFIG_FREERTOS_USE_STATS_FORMATTING_FUNCTIONS=y CONFIG_ESP_WIFI_SOFTAP_SUPPORT=n -# TODO - re-enable once resolved: https://github.com/espressif/esp-idf/issues/10322 -#CONFIG_COMPILER_OPTIMIZATION_SIZE=y +CONFIG_COMPILER_OPTIMIZATION_SIZE=y # Default sdkconfig parameters to use the OTA # partition table layout, with a 4MB flash size diff --git a/examples/esp_idf/cpp/sdkconfig.defaults b/examples/esp_idf/cpp/sdkconfig.defaults index 7117b2329..9d3bedc8d 100644 --- a/examples/esp_idf/cpp/sdkconfig.defaults +++ b/examples/esp_idf/cpp/sdkconfig.defaults @@ -8,8 +8,7 @@ CONFIG_FREERTOS_USE_TRACE_FACILITY=y CONFIG_FREERTOS_USE_STATS_FORMATTING_FUNCTIONS=y CONFIG_ESP_WIFI_SOFTAP_SUPPORT=n -# TODO - re-enable once resolved: https://github.com/espressif/esp-idf/issues/10322 -#CONFIG_COMPILER_OPTIMIZATION_SIZE=y +CONFIG_COMPILER_OPTIMIZATION_SIZE=y # GLTH_LOGX statements will automatically upload to Golioth Logs service CONFIG_GOLIOTH_AUTO_LOG_TO_CLOUD=1 diff --git a/examples/esp_idf/golioth_basics/sdkconfig.defaults b/examples/esp_idf/golioth_basics/sdkconfig.defaults index 88605acc2..dec16cb6f 100644 --- a/examples/esp_idf/golioth_basics/sdkconfig.defaults +++ b/examples/esp_idf/golioth_basics/sdkconfig.defaults @@ -8,10 +8,7 @@ CONFIG_FREERTOS_USE_TRACE_FACILITY=y CONFIG_FREERTOS_USE_STATS_FORMATTING_FUNCTIONS=y CONFIG_ESP_WIFI_SOFTAP_SUPPORT=n -# TODO - re-enable once resolved: https://github.com/espressif/esp-idf/issues/10322 -# Until then, optimize for performance, otherwise IRAM will overflow (BLE stack uses a lot of IRAM). -#CONFIG_COMPILER_OPTIMIZATION_SIZE=y -CONFIG_COMPILER_OPTIMIZATION_PERF=y +CONFIG_COMPILER_OPTIMIZATION_SIZE=y # OTA Partition Table CONFIG_ESPTOOLPY_FLASHSIZE_4MB=y diff --git a/examples/esp_idf/magtag_demo/sdkconfig.defaults b/examples/esp_idf/magtag_demo/sdkconfig.defaults index f71bbb2df..d6bc41f00 100644 --- a/examples/esp_idf/magtag_demo/sdkconfig.defaults +++ b/examples/esp_idf/magtag_demo/sdkconfig.defaults @@ -8,8 +8,7 @@ CONFIG_FREERTOS_USE_TRACE_FACILITY=y CONFIG_FREERTOS_USE_STATS_FORMATTING_FUNCTIONS=y CONFIG_ESP_WIFI_SOFTAP_SUPPORT=n -# TODO - re-enable once resolved: https://github.com/espressif/esp-idf/issues/10322 -#CONFIG_COMPILER_OPTIMIZATION_SIZE=y +CONFIG_COMPILER_OPTIMIZATION_SIZE=y # Refer to Adafruit schematic: # https://cdn-learn.adafruit.com/assets/assets/000/096/946/original/adafruit_products_MagTag_sch.png?1605026160 diff --git a/examples/esp_idf/test/sdkconfig.defaults b/examples/esp_idf/test/sdkconfig.defaults index c6aa4ac91..6aaddf965 100644 --- a/examples/esp_idf/test/sdkconfig.defaults +++ b/examples/esp_idf/test/sdkconfig.defaults @@ -8,8 +8,7 @@ CONFIG_FREERTOS_USE_TRACE_FACILITY=y CONFIG_FREERTOS_USE_STATS_FORMATTING_FUNCTIONS=y CONFIG_ESP_WIFI_SOFTAP_SUPPORT=n -# TODO - re-enable once resolved: https://github.com/espressif/esp-idf/issues/10322 -#CONFIG_COMPILER_OPTIMIZATION_SIZE=y +CONFIG_COMPILER_OPTIMIZATION_SIZE=y CONFIG_ESPTOOLPY_FLASHSIZE_4MB=y CONFIG_PARTITION_TABLE_CUSTOM=y @@ -24,5 +23,6 @@ CONFIG_ESP_SYSTEM_PANIC_PRINT_HALT=y CONFIG_LOG_DEFAULT_LEVEL_DEBUG=y CONFIG_UNITY_ENABLE_IDF_TEST_RUNNER=n CONFIG_GOLIOTH_ALLOCATION_TRACKING=1 +CONFIG_ESP_COREDUMP_DECODE=y CONFIG_GOLIOTH_COAP_HOST_URI="coaps://coap.golioth.dev" diff --git a/external/libcoap b/external/libcoap index 600eb783c..4abe0ea7a 160000 --- a/external/libcoap +++ b/external/libcoap @@ -1 +1 @@ -Subproject commit 600eb783c9b340ddac917db2273bc809341b5c65 +Subproject commit 4abe0ea7aae64edd28faf2e71750208954ca2efa diff --git a/port/esp_idf/components/coap/CMakeLists.txt b/port/esp_idf/components/coap/CMakeLists.txt index 5df73e2bc..919a624cc 100644 --- a/port/esp_idf/components/coap/CMakeLists.txt +++ b/port/esp_idf/components/coap/CMakeLists.txt @@ -5,30 +5,33 @@ set(sdk_port ${sdk_root}/port) set(libcoap_dir ${sdk_root}/external/libcoap) set(libcoap_srcs - "${libcoap_dir}/src/block.c" "${libcoap_dir}/src/coap_address.c" "${libcoap_dir}/src/coap_asn1.c" "${libcoap_dir}/src/coap_async.c" + "${libcoap_dir}/src/coap_block.c" "${libcoap_dir}/src/coap_cache.c" "${libcoap_dir}/src/coap_debug.c" + "${libcoap_dir}/src/coap_dtls.c" "${libcoap_dir}/src/coap_encode.c" "${libcoap_dir}/src/coap_event.c" "${libcoap_dir}/src/coap_hashkey.c" "${libcoap_dir}/src/coap_io.c" + "${libcoap_dir}/src/coap_layers.c" "${libcoap_dir}/src/coap_mbedtls.c" "${libcoap_dir}/src/coap_mem.c" - "${libcoap_dir}/src/coap_notls.c" + "${libcoap_dir}/src/coap_net.c" + "${libcoap_dir}/src/coap_netif.c" "${libcoap_dir}/src/coap_option.c" + "${libcoap_dir}/src/coap_pdu.c" "${libcoap_dir}/src/coap_prng.c" + "${libcoap_dir}/src/coap_resource.c" "${libcoap_dir}/src/coap_session.c" "${libcoap_dir}/src/coap_str.c" "${libcoap_dir}/src/coap_subscribe.c" "${libcoap_dir}/src/coap_tcp.c" "${libcoap_dir}/src/coap_time.c" "${libcoap_dir}/src/coap_uri.c" - "${libcoap_dir}/src/net.c" - "${libcoap_dir}/src/pdu.c" - "${libcoap_dir}/src/resource.c" + "${libcoap_dir}/src/coap_ws.c" ) idf_component_register( diff --git a/port/esp_idf/libcoap/include/coap3/coap.h b/port/esp_idf/libcoap/include/coap3/coap.h index add0787de..ee02a3acf 100644 --- a/port/esp_idf/libcoap/include/coap3/coap.h +++ b/port/esp_idf/libcoap/include/coap3/coap.h @@ -24,9 +24,9 @@ extern "C" { #include "coap3/libcoap.h" #include "coap3/coap_forward_decls.h" -#include "coap3/block.h" #include "coap3/coap_address.h" #include "coap3/coap_async.h" +#include "coap3/coap_block.h" #include "coap3/coap_cache.h" #include "coap3/coap_debug.h" #include "coap3/coap_dtls.h" @@ -36,13 +36,14 @@ extern "C" { #include "coap3/coap_mem.h" #include "coap3/coap_net.h" #include "coap3/coap_option.h" +#include "coap3/coap_pdu.h" #include "coap3/coap_prng.h" #include "coap3/coap_str.h" +#include "coap3/coap_resource.h" #include "coap3/coap_subscribe.h" #include "coap3/coap_time.h" #include "coap3/coap_uri.h" -#include "coap3/pdu.h" -#include "coap3/resource.h" +#include "coap3/coap_ws.h" #ifdef __cplusplus } diff --git a/port/esp_idf/libcoap/include/coap_config.h b/port/esp_idf/libcoap/include/coap_config.h index 04c6a9e84..6bf814622 100644 --- a/port/esp_idf/libcoap/include/coap_config.h +++ b/port/esp_idf/libcoap/include/coap_config.h @@ -40,4 +40,10 @@ #define HAVE_GETRANDOM +#define COAP_WITH_LIBMBEDTLS + +#define COAP_CLIENT_SUPPORT 1 +#define COAP_IPV4_SUPPORT 1 +#define COAP_WS_SUPPORT 0 + #endif /* _CONFIG_H_ */ diff --git a/port/zephyr/CMakeLists.txt b/port/zephyr/CMakeLists.txt index ec37c0bcd..a37390caa 100644 --- a/port/zephyr/CMakeLists.txt +++ b/port/zephyr/CMakeLists.txt @@ -73,30 +73,34 @@ zephyr_library_sources( ../../external/heatshrink/src/heatshrink_decoder.c # libcoap - ../../external/libcoap/src/block.c ../../external/libcoap/src/coap_address.c ../../external/libcoap/src/coap_asn1.c ../../external/libcoap/src/coap_async.c + ../../external/libcoap/src/coap_block.c ../../external/libcoap/src/coap_cache.c ../../external/libcoap/src/coap_debug.c + ../../external/libcoap/src/coap_dtls.c ../../external/libcoap/src/coap_encode.c ../../external/libcoap/src/coap_event.c ../../external/libcoap/src/coap_hashkey.c + ../../external/libcoap/src/coap_layers.c ../../external/libcoap/src/coap_mem.c + ../../external/libcoap/src/coap_net.c + ../../external/libcoap/src/coap_netif.c ../../external/libcoap/src/coap_option.c + ../../external/libcoap/src/coap_pdu.c ../../external/libcoap/src/coap_prng.c + ../../external/libcoap/src/coap_resource.c ../../external/libcoap/src/coap_session.c ../../external/libcoap/src/coap_str.c ../../external/libcoap/src/coap_subscribe.c ../../external/libcoap/src/coap_tcp.c ../../external/libcoap/src/coap_uri.c - ../../external/libcoap/src/net.c - ../../external/libcoap/src/pdu.c - ../../external/libcoap/src/resource.c - libcoap/io.c + ../../external/libcoap/src/coap_ws.c + libcoap/coap_io_zephyr.c + libcoap/coap_time.c + libcoap/coap_zephyrtls.c libcoap/log.c - libcoap/time.c - libcoap/tls.c # miniz ../../external/miniz/miniz_tinfl.c diff --git a/port/zephyr/libcoap/io.c b/port/zephyr/libcoap/coap_io_zephyr.c similarity index 90% rename from port/zephyr/libcoap/io.c rename to port/zephyr/libcoap/coap_io_zephyr.c index d9b5d8056..4b6eb38b6 100644 --- a/port/zephyr/libcoap/io.c +++ b/port/zephyr/libcoap/coap_io_zephyr.c @@ -36,10 +36,10 @@ unsigned int coap_io_prepare_io( *num_sockets = 0; -#ifndef WITHOUT_ASYNC +#if COAP_ASYNC_SUPPORT /* Check to see if we need to send off any Async requests */ timeout = coap_check_async(ctx, now); -#endif /* WITHOUT_ASYNC */ +#endif /* COAP_ASYNC_SUPPORT */ /* Check to see if we need to send off any retransmit request */ nextpdu = coap_peek_next(ctx); @@ -186,7 +186,7 @@ void coap_packet_get_memmapped(coap_packet_t* packet, unsigned char** address, s ssize_t coap_socket_send( coap_socket_t* sock, - coap_session_t* session, + const coap_session_t* session, const uint8_t* data, size_t data_len) { LOG_DBG("coap_socket_send()"); @@ -215,6 +215,16 @@ int coap_socket_connect_udp( goto close_socket; } + // If Connection IDs are enabled, set socket option to send CIDs, but not require that the + // server sends one in return. +#ifdef CONFIG_MBEDTLS_SSL_DTLS_CONNECTION_ID + int ENABLED = 1; + ret = zsock_setsockopt(sock->fd, SOL_TLS, TLS_DTLS_CID, &ENABLED, sizeof(ENABLED)); + if (ret < 0) { + goto close_socket; + } +#endif /* CONFIG_MBEDTLS_SSL_DTLS_CONNECTION_ID */ + if (session->proto == COAP_PROTO_UDP) { ret = zsock_connect(sock->fd, &connect_addr.addr.sa, connect_addr.size); if (ret < 0) { @@ -261,11 +271,11 @@ void coap_socket_close(coap_socket_t* sock) { sock->fd = -1; } -ssize_t coap_network_read(coap_socket_t* sock, coap_packet_t* packet) { +ssize_t coap_socket_recv(coap_socket_t* sock, coap_packet_t* packet) { ssize_t ret; if ((sock->flags & COAP_SOCKET_CAN_READ) == 0) { - LOG_DBG("coap_network_read: COAP_SOCKET_CAN_READ not set"); + LOG_DBG("coap_socket_recv: COAP_SOCKET_CAN_READ not set"); return -1; } @@ -273,7 +283,7 @@ ssize_t coap_network_read(coap_socket_t* sock, coap_packet_t* packet) { sock->flags &= ~COAP_SOCKET_CAN_READ; if (!(sock->flags & COAP_SOCKET_CONNECTED)) { - LOG_DBG("coap_network_read: !COAP_SOCKET_CONNECTED"); + LOG_DBG("coap_socket_recv: !COAP_SOCKET_CONNECTED"); return -1; } @@ -281,13 +291,13 @@ ssize_t coap_network_read(coap_socket_t* sock, coap_packet_t* packet) { if (ret < 0) { if (errno == ECONNREFUSED || errno == EHOSTUNREACH) { /* client-side ICMP destination unreachable, ignore it */ - LOG_WRN("%s: coap_network_read: ICMP: %s", + LOG_WRN("%s: coap_socket_recv: ICMP: %s", sock->session ? coap_session_str(sock->session) : "", strerror(errno)); return -2; } - LOG_WRN("%s: coap_network_read: %s", + LOG_WRN("%s: coap_socket_recv: %s", sock->session ? coap_session_str(sock->session) : "", strerror(errno)); @@ -306,10 +316,11 @@ ssize_t coap_network_read(coap_socket_t* sock, coap_packet_t* packet) { return -1; } -ssize_t coap_network_send( - coap_socket_t* sock, - const coap_session_t* session, - const uint8_t* data, - size_t datalen) { - return -1; +const char * +coap_socket_format_errno(int error) { + return strerror(error); +} +const char * +coap_socket_strerror(void) { + return coap_socket_format_errno(errno); } diff --git a/port/zephyr/libcoap/time.c b/port/zephyr/libcoap/coap_time.c similarity index 100% rename from port/zephyr/libcoap/time.c rename to port/zephyr/libcoap/coap_time.c diff --git a/port/zephyr/libcoap/tls.c b/port/zephyr/libcoap/coap_zephyrtls.c similarity index 98% rename from port/zephyr/libcoap/tls.c rename to port/zephyr/libcoap/coap_zephyrtls.c index 30d10211b..d7d5e0834 100644 --- a/port/zephyr/libcoap/tls.c +++ b/port/zephyr/libcoap/coap_zephyrtls.c @@ -111,7 +111,7 @@ int coap_dtls_zephyr_connect(coap_session_t* session) { } int coap_dtls_send(coap_session_t* session, const uint8_t* data, size_t data_len) { - return coap_session_send(session, data, data_len); + return (int)session->sock.lfunc[COAP_LAYER_TLS].l_write(session, data, data_len); } void coap_dtls_startup(void) {} diff --git a/port/zephyr/libcoap/include/coap3/coap.h b/port/zephyr/libcoap/include/coap3/coap.h index 9ca7ddc73..6ae9cdb07 100644 --- a/port/zephyr/libcoap/include/coap3/coap.h +++ b/port/zephyr/libcoap/include/coap3/coap.h @@ -8,9 +8,9 @@ extern "C" { #include "coap3/libcoap.h" #include "coap3/coap_forward_decls.h" -#include "coap3/block.h" #include "coap3/coap_address.h" #include "coap3/coap_async.h" +#include "coap3/coap_block.h" #include "coap3/coap_cache.h" #include "coap3/coap_debug.h" #include "coap3/coap_dtls.h" @@ -20,13 +20,14 @@ extern "C" { #include "coap3/coap_mem.h" #include "coap3/coap_net.h" #include "coap3/coap_option.h" +#include "coap3/coap_pdu.h" #include "coap3/coap_prng.h" #include "coap3/coap_str.h" +#include "coap3/coap_resource.h" #include "coap3/coap_subscribe.h" #include "coap3/coap_time.h" #include "coap3/coap_uri.h" -#include "coap3/pdu.h" -#include "coap3/resource.h" +#include "coap3/coap_ws.h" #ifdef __cplusplus } diff --git a/src/golioth_coap_client.c b/src/golioth_coap_client.c index 77fbd0317..674f1f7c9 100644 --- a/src/golioth_coap_client.c +++ b/src/golioth_coap_client.c @@ -948,7 +948,6 @@ static void golioth_coap_client_thread(void* arg) { coap_free_context(coap_context); GSTATS_INC_FREE("context"); } - coap_cleanup(); // Small delay before starting a new session golioth_sys_msleep(1000); @@ -967,6 +966,9 @@ golioth_client_t golioth_client_create(const golioth_client_config_t* config) { time_t t; srand(time(&t)); + // Initialize libcoap prior to any coap_* function calls. + coap_startup(); + _initialized = true; }