ot_br: skip network configuration if dataset is active

pull/7554/head
WangQixiang 2021-09-02 15:03:30 +08:00
rodzic 1a19014d3d
commit 321f301e3e
1 zmienionych plików z 12 dodań i 1 usunięć

Wyświetl plik

@ -92,6 +92,12 @@ static size_t hex_string_to_binary(const char *hex_string, uint8_t *buf, size_t
static void create_config_network(otInstance *instance) static void create_config_network(otInstance *instance)
{ {
otOperationalDataset dataset; otOperationalDataset dataset;
if (otDatasetGetActive(instance, &dataset) == OT_ERROR_NONE) {
ESP_LOGI(TAG, "Already has network, skip configuring OpenThread network.");
return;
}
uint16_t network_name_len = strnlen(CONFIG_OPENTHREAD_NETWORK_NAME, OT_NETWORK_NAME_MAX_SIZE + 1); uint16_t network_name_len = strnlen(CONFIG_OPENTHREAD_NETWORK_NAME, OT_NETWORK_NAME_MAX_SIZE + 1);
assert(network_name_len <= OT_NETWORK_NAME_MAX_SIZE); assert(network_name_len <= OT_NETWORK_NAME_MAX_SIZE);
@ -132,6 +138,11 @@ static void create_config_network(otInstance *instance)
ESP_LOGE(TAG, "Failed to register border router."); ESP_LOGE(TAG, "Failed to register border router.");
abort(); abort();
} }
return;
}
static void launch_openthread_network(otInstance *instance)
{
if (otIp6SetEnabled(instance, true) != OT_ERROR_NONE) { if (otIp6SetEnabled(instance, true) != OT_ERROR_NONE) {
ESP_LOGE(TAG, "Failed to enable OpenThread IP6 link"); ESP_LOGE(TAG, "Failed to enable OpenThread IP6 link");
abort(); abort();
@ -140,7 +151,6 @@ static void create_config_network(otInstance *instance)
ESP_LOGE(TAG, "Failed to enable OpenThread"); ESP_LOGE(TAG, "Failed to enable OpenThread");
abort(); abort();
} }
return;
} }
static void ot_task_worker(void *aContext) static void ot_task_worker(void *aContext)
@ -165,6 +175,7 @@ static void ot_task_worker(void *aContext)
esp_openthread_lock_acquire(portMAX_DELAY); esp_openthread_lock_acquire(portMAX_DELAY);
otAppCliInit(esp_openthread_get_instance()); otAppCliInit(esp_openthread_get_instance());
create_config_network(esp_openthread_get_instance()); create_config_network(esp_openthread_get_instance());
launch_openthread_network(esp_openthread_get_instance());
esp_openthread_lock_release(); esp_openthread_lock_release();
// Run the main loop // Run the main loop