Merge branch 'fix/handle_escape_characters_v5.4' into 'release/v5.4'

Fix/handle escape characters (v5.4)

See merge request espressif/esp-idf!48097
This commit is contained in:
Zhang Wen Xu
2026-04-30 06:34:59 +00:00
3 changed files with 37 additions and 4 deletions
+31 -2
View File
@@ -27,6 +27,31 @@
static TaskHandle_t s_cli_task;
static bool append_escaped_ot_arg(char *buffer, size_t buffer_size, const char *arg)
{
size_t len = strlen(buffer);
size_t rem_size = (len < buffer_size) ? (buffer_size - len - 1) : 0;
ESP_RETURN_ON_FALSE(rem_size > 0, false, OT_PLAT_LOG_TAG, "CLI command buffer is full");
while (*arg) {
bool need_escape = (*arg == ' ') || (*arg == '\t') || (*arg == '\r') || (*arg == '\n') || (*arg == '\\');
size_t need = need_escape ? 2 : 1;
ESP_RETURN_ON_FALSE(rem_size >= need, false, OT_PLAT_LOG_TAG, "CLI command is too long");
if (need_escape) {
buffer[len++] = '\\';
}
buffer[len++] = *arg++;
rem_size -= need;
}
buffer[len] = '\0';
return true;
}
static int cli_output_callback(void *context, const char *format, va_list args)
{
char prompt_check[3];
@@ -75,10 +100,14 @@ static int ot_cli_console_callback(int argc, char **argv)
{
ESP_RETURN_ON_FALSE(argv[1] != NULL && strlen(argv[1]) > 0, ESP_FAIL, OT_PLAT_LOG_TAG, "Invalid OpenThread command");
char cli_cmd[OT_CLI_MAX_LINE_LENGTH] = {0};
strncpy(cli_cmd, argv[1], sizeof(cli_cmd) - strlen(cli_cmd) - 1);
ESP_RETURN_ON_FALSE(append_escaped_ot_arg(cli_cmd, sizeof(cli_cmd), argv[1]), ESP_FAIL, OT_PLAT_LOG_TAG,
"Failed to compose OpenThread command");
for (int i = 2; i < argc; i++) {
ESP_RETURN_ON_FALSE(strlen(cli_cmd) < sizeof(cli_cmd) - 1, ESP_FAIL, OT_PLAT_LOG_TAG,
"CLI command is too long");
strncat(cli_cmd, " ", sizeof(cli_cmd) - strlen(cli_cmd) - 1);
strncat(cli_cmd, argv[i], sizeof(cli_cmd) - strlen(cli_cmd) - 1);
ESP_RETURN_ON_FALSE(append_escaped_ot_arg(cli_cmd, sizeof(cli_cmd), argv[i]), ESP_FAIL, OT_PLAT_LOG_TAG,
"Failed to compose OpenThread command");
}
s_cli_task = xTaskGetCurrentTaskHandle();
if (esp_openthread_cli_input(cli_cmd) == ESP_OK) {
@@ -53,7 +53,9 @@ static otRadioCaps s_radio_caps = (OT_RADIO_CAPS_ENERGY_SCAN |
OT_RADIO_CAPS_RECEIVE_TIMING |
OT_RADIO_CAPS_TRANSMIT_TIMING |
OT_RADIO_CAPS_ACK_TIMEOUT |
OT_RADIO_CAPS_SLEEP_TO_TX);
OT_RADIO_CAPS_SLEEP_TO_TX |
OT_RADIO_CAPS_CSMA_BACKOFF |
OT_RADIO_CAPS_TRANSMIT_RETRIES);
static const char *radiospinel_workflow = "radio_spinel";
static const esp_openthread_radio_config_t *s_esp_openthread_radio_config = NULL;
@@ -40,7 +40,9 @@ static otRadioCaps s_radio_caps = (OT_RADIO_CAPS_ENERGY_SCAN |
OT_RADIO_CAPS_RECEIVE_TIMING |
OT_RADIO_CAPS_TRANSMIT_TIMING |
OT_RADIO_CAPS_ACK_TIMEOUT |
OT_RADIO_CAPS_SLEEP_TO_TX);
OT_RADIO_CAPS_SLEEP_TO_TX |
OT_RADIO_CAPS_CSMA_BACKOFF |
OT_RADIO_CAPS_TRANSMIT_RETRIES);
static esp_radio_spinel_compatibility_error_callback s_radio_spinel_compatibility_error_callback = NULL;
static esp_radio_spinel_coprocessor_reset_failure_callback s_radio_spinel_coprocessor_reset_failure_callback = NULL;