From 0998f3dd4fd3f5afab5be98d9e52798000b5d3c2 Mon Sep 17 00:00:00 2001 From: David Cermak Date: Tue, 9 Jan 2024 11:13:17 +0100 Subject: [PATCH] fix(modem): Fixed incorrect dial command format ATD command is used to switch generic device to the data mode by dialing GPRS_SRC. The generic version of the command was incorrect `ATD*99##` (containing extra trailing # char, which is accepted by most devices). Command has been fixed, but the extra #'s been kept for devices that we cannot test (to be fixed in IDFGH-9470). Closes https://github.com/espressif/esp-protocols/issues/433 --- .../cxx_include/esp_modem_command_library.hpp | 2 +- .../include/cxx_include/esp_modem_dce_module.hpp | 3 ++- .../esp_modem/src/esp_modem_command_library.cpp | 6 +++--- components/esp_modem/src/esp_modem_modules.cpp | 12 ++++++------ .../esp_modem/test/host_test/main/LoopbackTerm.cpp | 7 +++++-- 5 files changed, 17 insertions(+), 13 deletions(-) diff --git a/components/esp_modem/include/cxx_include/esp_modem_command_library.hpp b/components/esp_modem/include/cxx_include/esp_modem_command_library.hpp index 9b732fe50..d0e133eeb 100644 --- a/components/esp_modem/include/cxx_include/esp_modem_command_library.hpp +++ b/components/esp_modem/include/cxx_include/esp_modem_command_library.hpp @@ -54,7 +54,7 @@ command_result power_down_sim76xx(CommandableIf *t); command_result power_down_sim70xx(CommandableIf *t); command_result set_network_bands_sim76xx(CommandableIf *t, const std::string &mode, const int *bands, int size); command_result power_down_sim8xx(CommandableIf *t); -command_result set_data_mode_sim8xx(CommandableIf *t); +command_result set_data_mode_alt(CommandableIf *t); command_result set_pdp_context(CommandableIf *t, PdpContext &pdp, uint32_t timeout_ms); /** diff --git a/components/esp_modem/include/cxx_include/esp_modem_dce_module.hpp b/components/esp_modem/include/cxx_include/esp_modem_dce_module.hpp index cc08c537d..6ae36e63e 100644 --- a/components/esp_modem/include/cxx_include/esp_modem_dce_module.hpp +++ b/components/esp_modem/include/cxx_include/esp_modem_dce_module.hpp @@ -144,6 +144,8 @@ class SIM7070: public GenericModule { using GenericModule::GenericModule; public: command_result power_down() override; + command_result set_data_mode() override; + }; /** @@ -162,7 +164,6 @@ class SIM800: public GenericModule { using GenericModule::GenericModule; public: command_result power_down() override; - command_result set_data_mode() override; }; /** diff --git a/components/esp_modem/src/esp_modem_command_library.cpp b/components/esp_modem/src/esp_modem_command_library.cpp index 6226f151c..46e005db0 100644 --- a/components/esp_modem/src/esp_modem_command_library.cpp +++ b/components/esp_modem/src/esp_modem_command_library.cpp @@ -277,13 +277,13 @@ command_result set_pdp_context(CommandableIf *t, PdpContext &pdp) command_result set_data_mode(CommandableIf *t) { ESP_LOGV(TAG, "%s", __func__ ); - return generic_command(t, "ATD*99##\r", "CONNECT", "ERROR", 5000); + return generic_command(t, "ATD*99#\r", "CONNECT", "ERROR", 5000); } -command_result set_data_mode_sim8xx(CommandableIf *t) +command_result set_data_mode_alt(CommandableIf *t) { ESP_LOGV(TAG, "%s", __func__ ); - return generic_command(t, "ATD*99#\r", "CONNECT", "ERROR", 5000); + return generic_command(t, "ATD*99##\r", "CONNECT", "ERROR", 5000); } command_result resume_data_mode(CommandableIf *t) diff --git a/components/esp_modem/src/esp_modem_modules.cpp b/components/esp_modem/src/esp_modem_modules.cpp index a3c6801e3..563403494 100644 --- a/components/esp_modem/src/esp_modem_modules.cpp +++ b/components/esp_modem/src/esp_modem_modules.cpp @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2021-2023 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2021-2024 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -67,6 +67,11 @@ command_result SIM7070::power_down() return dce_commands::power_down_sim70xx(dte.get()); } +command_result SIM7070::set_data_mode() +{ + return dce_commands::set_data_mode_alt(dte.get()); +} + command_result SIM7000::power_down() { return dce_commands::power_down_sim70xx(dte.get()); @@ -77,11 +82,6 @@ command_result SIM800::power_down() return dce_commands::power_down_sim8xx(dte.get()); } -command_result SIM800::set_data_mode() -{ - return dce_commands::set_data_mode_sim8xx(dte.get()); -} - command_result BG96::set_pdp_context(esp_modem::PdpContext &pdp) { return dce_commands::set_pdp_context(dte.get(), pdp, 300); diff --git a/components/esp_modem/test/host_test/main/LoopbackTerm.cpp b/components/esp_modem/test/host_test/main/LoopbackTerm.cpp index e230fea2c..935c634fa 100644 --- a/components/esp_modem/test/host_test/main/LoopbackTerm.cpp +++ b/components/esp_modem/test/host_test/main/LoopbackTerm.cpp @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2022-2023 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2022-2024 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Unlicense OR CC0-1.0 */ @@ -36,7 +36,7 @@ int LoopbackTerm::write(uint8_t *data, size_t len) } else if (command == "ATO\r") { response = "ERROR\r\n"; } else if (command.find("ATD") != std::string::npos) { - response = "CONNECT\r\n"; + response = "CONNECT\n"; } else if (command.find("AT+CSQ\r") != std::string::npos) { response = "+CSQ: 123,456\n\r\nOK\r\n"; } else if (command.find("AT+CGMM\r") != std::string::npos) { @@ -74,6 +74,9 @@ int LoopbackTerm::write(uint8_t *data, size_t len) } if (len > 2 && data[0] == 0xf9) { // Simple CMUX responder // turn the request into a reply -> implements CMUX loopback + // Note: This simple CMUX responder only updates CMUX headers and replaces payload. + // It means that all responses (that we test) must be shorter or equal to the requests + // For example ATD (dial command): sizeof("ATD*99#") >= sizeof("CONNECT"); if (data[2] == 0x3f || data[2] == 0x53) { // SABM command data[2] = 0x73; } else if (data[2] == 0xef) { // Generic request