diff --git a/components/openthread/src/esp_openthread_cli.c b/components/openthread/src/esp_openthread_cli.c index 83bda1d2ca3..c709e5889b3 100644 --- a/components/openthread/src/esp_openthread_cli.c +++ b/components/openthread/src/esp_openthread_cli.c @@ -60,6 +60,31 @@ static void ot_cli_set_read_characteristics(void) linenoiseSetReadFunction(ot_cli_read_bytes); } +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]; @@ -108,10 +133,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) { diff --git a/components/openthread/src/port/esp_openthread_radio_spinel.cpp b/components/openthread/src/port/esp_openthread_radio_spinel.cpp index f9695b23871..fa8c2e3f5a0 100644 --- a/components/openthread/src/port/esp_openthread_radio_spinel.cpp +++ b/components/openthread/src/port/esp_openthread_radio_spinel.cpp @@ -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; diff --git a/components/openthread/src/spinel/esp_radio_spinel.cpp b/components/openthread/src/spinel/esp_radio_spinel.cpp index 3c35b0cbd8b..06ed3bc6e21 100644 --- a/components/openthread/src/spinel/esp_radio_spinel.cpp +++ b/components/openthread/src/spinel/esp_radio_spinel.cpp @@ -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;