From ce7daddc779d3e9a44565b35f1a1844a77386073 Mon Sep 17 00:00:00 2001 From: David Cermak Date: Wed, 17 Jan 2024 12:50:32 +0100 Subject: [PATCH 1/3] fix(modem): Added C-API to configure APN Closes https://github.com/espressif/esp-protocols/issues/485 --- .../esp_modem/include/esp_modem_c_api_types.h | 21 ++++++++++++++++++- components/esp_modem/src/esp_modem_c_api.cpp | 7 +++++++ 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/components/esp_modem/include/esp_modem_c_api_types.h b/components/esp_modem/include/esp_modem_c_api_types.h index fcc54701c8..2c74819ab7 100644 --- a/components/esp_modem/include/esp_modem_c_api_types.h +++ b/components/esp_modem/include/esp_modem_c_api_types.h @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2021-2022 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2021-2024 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -119,8 +119,27 @@ esp_err_t esp_modem_set_error_cb(esp_modem_dce_t *dce, esp_modem_terminal_error_ */ esp_err_t esp_modem_set_mode(esp_modem_dce_t *dce, esp_modem_dce_mode_t mode); +/** + * @brief Convenient function to run arbitrary commands from C-API + * + * @param dce Modem DCE handle + * @param command Command to send + * @param got_line_cb Callback function which is called whenever we receive a line + * @param timeout_ms Command timeout + * @return ESP_OK on success, ESP_FAIL on failure + */ + esp_err_t esp_modem_command(esp_modem_dce_t *dce, const char *command, esp_err_t(*got_line_cb)(uint8_t *data, size_t len), uint32_t timeout_ms); +/** + * @brief Sets the APN and configures it into the modem's PDP context + * + * @param dce Modem DCE handle + * @param apn Access Point Name + * @return ESP_OK on success + */ +esp_err_t esp_modem_set_apn(esp_modem_dce_t *dce, const char *apn); + /** * @} */ diff --git a/components/esp_modem/src/esp_modem_c_api.cpp b/components/esp_modem/src/esp_modem_c_api.cpp index 6c32cf8c67..033e6f72a1 100644 --- a/components/esp_modem/src/esp_modem_c_api.cpp +++ b/components/esp_modem/src/esp_modem_c_api.cpp @@ -448,3 +448,10 @@ extern "C" esp_err_t esp_modem_set_baud(esp_modem_dce_t *dce_wrap, int baud) { return command_response_to_esp_err(dce_wrap->dce->set_baud(baud)); } + +extern "C" esp_err_t esp_modem_set_apn(esp_modem_dce_t *dce_wrap, const char *apn) +{ + auto new_pdp = std::unique_ptr(new PdpContext(apn)); + dce_wrap->dce->get_module()->configure_pdp_context(std::move(new_pdp)); + return ESP_OK; +} From 1dc4299eb0a11ee97bd5f2cea3ce7de676c66463 Mon Sep 17 00:00:00 2001 From: David Cermak Date: Wed, 17 Jan 2024 17:43:47 +0100 Subject: [PATCH 2/3] fix(modem): Fixed OTA test to gracefully fail with no verification --- .../test/target_ota/components/manual_ota/manual_ota.cpp | 4 ++++ .../test/target_ota/components/manual_ota/manual_ota.hpp | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/components/esp_modem/test/target_ota/components/manual_ota/manual_ota.cpp b/components/esp_modem/test/target_ota/components/manual_ota/manual_ota.cpp index c78c9b4e46..d2c6e2e100 100644 --- a/components/esp_modem/test/target_ota/components/manual_ota/manual_ota.cpp +++ b/components/esp_modem/test/target_ota/components/manual_ota/manual_ota.cpp @@ -35,6 +35,10 @@ bool manual_ota::begin() esp_transport_handle_t tcp = esp_transport_tcp_init(); ssl_ = esp_transport_batch_tls_init(tcp, max_buffer_size_); http_.config_.transport = ssl_; + if (http_.config_.cert_pem == nullptr || common_name_ == nullptr) { + ESP_LOGE(TAG, "TLS with no verification is not supported"); + return fail(); + } if (!esp_transport_batch_set_ca_cert(ssl_, http_.config_.cert_pem, 0)) { return fail(); } diff --git a/components/esp_modem/test/target_ota/components/manual_ota/manual_ota.hpp b/components/esp_modem/test/target_ota/components/manual_ota/manual_ota.hpp index baa1302a9a..1e5d874834 100644 --- a/components/esp_modem/test/target_ota/components/manual_ota/manual_ota.hpp +++ b/components/esp_modem/test/target_ota/components/manual_ota/manual_ota.hpp @@ -40,7 +40,7 @@ class manual_ota { /** * @brief Set common name of the server to verify */ - const char *common_name_; + const char *common_name_{}; /** * @brief Wrapper around the http client -- Please set the http config */ From 68ce794098da0f1690daf32248045e231d87c60b Mon Sep 17 00:00:00 2001 From: David Cermak Date: Thu, 18 Jan 2024 08:13:20 +0100 Subject: [PATCH 3/3] docs(modem): Added description of manual test procedure --- components/esp_modem/test/README.md | 47 +++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 components/esp_modem/test/README.md diff --git a/components/esp_modem/test/README.md b/components/esp_modem/test/README.md new file mode 100644 index 0000000000..5d4eebdafe --- /dev/null +++ b/components/esp_modem/test/README.md @@ -0,0 +1,47 @@ +# ESP-Modem Testing + +This folder contains automated and manual tests for esp-modem component. Beside these tests, some jobs are executed in CI to exercise standard examples (please refer to the CI definition and CI related sdkconfigs in examples). + +List of test projects: + +* `host_test` -- esp_modem is build on host (linux), modem's terminal in mocked using Loobpack class which creates simple responders to AT and CMUX mode. This test is executed in CI. +* `target` -- test executed on target with no modem device, just a pppd running on the test runner. This test is executed in CI. +* `target_ota` -- Manual test which perform OTA over PPP. +* `target_iperf` -- Manual test to measure data throughput via PPP. + +## Manual testing + +Prior to every `esp_modem` release, these manual tests must be executed and pass +(IDF-9074 to move the manual tests to CI) + +### `target_ota` + +Make sure that the UART ISR is not in IRAM, so the error messages are expected in the log, but the ESP32 should recover and continue with downloading the image. + +Perform the test for these devices +* SIM7600 (CMUX mode) +* BG96 (CMUX mode) +* SIM7000 (PPP mode) +* A7672 (CMUX mode -- the only device with 2 byte CMUX payload), so the test is expected to fail more often if (`CONFIG_ESP_MODEM_CMUX_DEFRAGMENT_PAYLOAD=y` && `CONFIG_ESP_MODEM_USE_INFLATABLE_BUFFER_IF_NEEDED=n` && dte_buffer < device max payload) +* NetworkDCE -- no modem device, pppd (PPP mode) + +Perform the test with these configurations: +* CONFIG_TEST_USE_VFS_TERM (y/n) +* CONFIG_ESP_HTTP_CLIENT_ENABLE_CUSTOM_TRANSPORT (y/n) +* CONFIG_ESP_MODEM_CMUX_DEFRAGMENT_PAYLOAD (y/n) +* CONFIG_ESP_MODEM_USE_INFLATABLE_BUFFER_IF_NEEDED (y/n) + +**Criteria for passing the test** + +The test should complete the download with maximum 1 retry (50% of OTA failure) +In case of CMUX mode, we're trying to exit CMUX at the end of the test. This step might also fail for some devices, as the CMUX-exit is not supported on certain devices (when the final error message appears that the device failed to exit CMUX, we just verify the new image by reseting the ESP32) + +### `target_iperf` + +Run these 4 `iperf` configurations (either manually or using `pytest`): +* tcp_tx_throughput +* tcp_rx_throughput +* udp_tx_throughput +* udp_rx_throughput + +And verify in all four cases the value is about 0.70 Mbps