From 5435c9b04afe7ccfbb63c4de3f9ee548f993d410 Mon Sep 17 00:00:00 2001 From: WanqQixiang Date: Mon, 18 Sep 2023 10:49:03 +0800 Subject: [PATCH] fix(protocomm): Remove the configuration check of wifi_provisioning for protocomm component --- components/protocomm/Kconfig | 13 +++++++++ .../protocomm/src/simple_ble/simple_ble.c | 2 -- .../protocomm/src/simple_ble/simple_ble.h | 2 -- .../protocomm/src/transports/protocomm_ble.c | 28 ++++++++---------- .../src/transports/protocomm_nimble.c | 29 +++++++++---------- components/wifi_provisioning/Kconfig | 2 ++ 6 files changed, 40 insertions(+), 36 deletions(-) diff --git a/components/protocomm/Kconfig b/components/protocomm/Kconfig index 312d10d679..545791443c 100644 --- a/components/protocomm/Kconfig +++ b/components/protocomm/Kconfig @@ -26,4 +26,17 @@ menu "Protocomm" Disabling this option saves some code size. Consult the Enabling protocomm security version section of the Protocomm documentation in ESP-IDF Programming guide for more details. + + config ESP_PROTOCOMM_KEEP_BLE_ON_AFTER_BLE_STOP + bool + depends on BT_ENABLED + help + Keep BT on after calling protocomm_ble_stop + + config ESP_PROTOCOMM_DISCONNECT_AFTER_BLE_STOP + bool + depends on ESP_PROTOCOMM_KEEP_BLE_ON_AFTER_BLE_STOP + help + Terminate connection after calling protocomm_ble_stop + endmenu diff --git a/components/protocomm/src/simple_ble/simple_ble.c b/components/protocomm/src/simple_ble/simple_ble.c index 2cc49c6eef..426fcc2dce 100644 --- a/components/protocomm/src/simple_ble/simple_ble.c +++ b/components/protocomm/src/simple_ble/simple_ble.c @@ -326,9 +326,7 @@ esp_err_t simple_ble_stop(void) return ESP_OK; } -#ifdef CONFIG_WIFI_PROV_DISCONNECT_AFTER_PROV esp_err_t simple_ble_disconnect(void) { return esp_ble_gap_disconnect(s_cached_remote_bda); } -#endif diff --git a/components/protocomm/src/simple_ble/simple_ble.h b/components/protocomm/src/simple_ble/simple_ble.h index 78fe930379..06d2bfa7b2 100644 --- a/components/protocomm/src/simple_ble/simple_ble.h +++ b/components/protocomm/src/simple_ble/simple_ble.h @@ -104,7 +104,6 @@ esp_err_t simple_ble_stop(void); */ const uint8_t *simple_ble_get_uuid128(uint16_t handle); -#ifdef CONFIG_WIFI_PROV_DISCONNECT_AFTER_PROV /** Terminates connection * * This API is called to initiate disconnection @@ -112,5 +111,4 @@ const uint8_t *simple_ble_get_uuid128(uint16_t handle); * @return ESP_OK on success, and appropriate error code for failure */ esp_err_t simple_ble_disconnect(void); -#endif #endif /* _SIMPLE_BLE_ */ diff --git a/components/protocomm/src/transports/protocomm_ble.c b/components/protocomm/src/transports/protocomm_ble.c index 901c70026d..6c070e4001 100644 --- a/components/protocomm/src/transports/protocomm_ble.c +++ b/components/protocomm/src/transports/protocomm_ble.c @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2018-2021 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2018-2023 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -332,13 +332,11 @@ static void transport_simple_ble_disconnect(esp_gatts_cb_event_t event, esp_gatt esp_err_t ret; ESP_LOGD(TAG, "Inside disconnect w/ session - %d", param->disconnect.conn_id); -#ifdef CONFIG_WIFI_PROV_KEEP_BLE_ON_AFTER_PROV /* Ignore BLE events received after protocomm layer is stopped */ if (protoble_internal == NULL) { ESP_LOGI(TAG,"Protocomm layer has already stopped"); return; } -#endif if (protoble_internal->pc_ble->sec && protoble_internal->pc_ble->sec->close_transport_session) { @@ -360,13 +358,11 @@ static void transport_simple_ble_connect(esp_gatts_cb_event_t event, esp_gatt_if esp_err_t ret; ESP_LOGD(TAG, "Inside BLE connect w/ conn_id - %d", param->connect.conn_id); -#ifdef CONFIG_WIFI_PROV_KEEP_BLE_ON_AFTER_PROV /* Ignore BLE events received after protocomm layer is stopped */ if (protoble_internal == NULL) { ESP_LOGI(TAG,"Protocomm layer has already stopped"); return; } -#endif if (protoble_internal->pc_ble->sec && protoble_internal->pc_ble->sec->new_transport_session) { @@ -613,23 +609,23 @@ esp_err_t protocomm_ble_stop(protocomm_t *pc) (pc == protoble_internal->pc_ble)) { esp_err_t ret = ESP_OK; -#ifndef CONFIG_WIFI_PROV_KEEP_BLE_ON_AFTER_PROV - /* If flag is not enabled, stop the stack. */ - ret = simple_ble_stop(); - if (ret) { - ESP_LOGE(TAG, "BLE stop failed"); - } - simple_ble_deinit(); -#else -#ifdef CONFIG_WIFI_PROV_DISCONNECT_AFTER_PROV +#ifdef CONFIG_ESP_PROTOCOMM_KEEP_BLE_ON_AFTER_BLE_STOP +#ifdef CONFIG_ESP_PROTOCOMM_DISCONNECT_AFTER_BLE_STOP /* Keep BT stack on, but terminate the connection after provisioning */ ret = simple_ble_disconnect(); if (ret) { ESP_LOGE(TAG, "BLE disconnect failed"); } simple_ble_deinit(); -#endif // CONFIG_WIFI_PROV_DISCONNECT_AFTER_PROV -#endif // CONFIG_WIFI_PROV_KEEP_BLE_ON_AFTER_PROV +#endif // CONFIG_ESP_PROTOCOMM_DISCONNECT_AFTER_BLE_STOP +#else + /* If flag is not enabled, stop the stack. */ + ret = simple_ble_stop(); + if (ret) { + ESP_LOGE(TAG, "BLE stop failed"); + } + simple_ble_deinit(); +#endif // CONFIG_ESP_PROTOCOMM_KEEP_BLE_ON_AFTER_BLE_STOP protocomm_ble_cleanup(); return ret; diff --git a/components/protocomm/src/transports/protocomm_nimble.c b/components/protocomm/src/transports/protocomm_nimble.c index 2d3dee3fc4..29db394071 100644 --- a/components/protocomm/src/transports/protocomm_nimble.c +++ b/components/protocomm/src/transports/protocomm_nimble.c @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2019-2021 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2019-2023 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -556,13 +556,12 @@ static void transport_simple_ble_disconnect(struct ble_gap_event *event, void *a ESP_LOGD(TAG, "Inside disconnect w/ session - %d", event->disconnect.conn.conn_handle); -#ifdef CONFIG_WIFI_PROV_KEEP_BLE_ON_AFTER_PROV /* Ignore BLE events received after protocomm layer is stopped */ if (protoble_internal == NULL) { ESP_LOGI(TAG,"Protocomm layer has already stopped"); return; } -#endif + if (protoble_internal->pc_ble->sec && protoble_internal->pc_ble->sec->close_transport_session) { ret = @@ -583,13 +582,11 @@ static void transport_simple_ble_connect(struct ble_gap_event *event, void *arg) esp_err_t ret; ESP_LOGD(TAG, "Inside BLE connect w/ conn_id - %d", event->connect.conn_handle); -#ifdef CONFIG_WIFI_PROV_KEEP_BLE_ON_AFTER_PROV /* Ignore BLE events received after protocomm layer is stopped */ if (protoble_internal == NULL) { ESP_LOGI(TAG,"Protocomm layer has already stopped"); return; } -#endif if (protoble_internal->pc_ble->sec && protoble_internal->pc_ble->sec->new_transport_session) { @@ -993,23 +990,23 @@ esp_err_t protocomm_ble_stop(protocomm_t *pc) rc); } -#ifndef CONFIG_WIFI_PROV_KEEP_BLE_ON_AFTER_PROV - /* If flag is enabled, don't stop the stack. User application can start a new advertising to perform its BT activities */ - ret = nimble_port_stop(); - if (ret == 0) { - nimble_port_deinit(); - } - free_gatt_ble_misc_memory(ble_cfg_p); -#else -#ifdef CONFIG_WIFI_PROV_DISCONNECT_AFTER_PROV +#ifdef CONFIG_ESP_PROTOCOMM_KEEP_BLE_ON_AFTER_BLE_STOP +#ifdef CONFIG_ESP_PROTOCOMM_DISCONNECT_AFTER_BLE_STOP /* Keep BT stack on, but terminate the connection after provisioning */ rc = ble_gap_terminate(s_cached_conn_handle, BLE_ERR_REM_USER_CONN_TERM); if (rc) { ESP_LOGI(TAG, "Error in terminating connection rc = %d",rc); } free_gatt_ble_misc_memory(ble_cfg_p); -#endif // CONFIG_WIFI_PROV_DISCONNECT_AFTER_PROV -#endif // CONFIG_WIFI_PROV_KEEP_BLE_ON_AFTER_PROV +#endif // CONFIG_ESP_PROTOCOMM_DISCONNECT_AFTER_BLE_STOP +#else + /* If flag is enabled, don't stop the stack. User application can start a new advertising to perform its BT activities */ + ret = nimble_port_stop(); + if (ret == 0) { + nimble_port_deinit(); + } + free_gatt_ble_misc_memory(ble_cfg_p); +#endif // CONFIG_ESP_PROTOCOMM_KEEP_BLE_ON_AFTER_BLE_STOP protocomm_ble_cleanup(); return ret; diff --git a/components/wifi_provisioning/Kconfig b/components/wifi_provisioning/Kconfig index ea0714663d..9403d0ee23 100644 --- a/components/wifi_provisioning/Kconfig +++ b/components/wifi_provisioning/Kconfig @@ -39,11 +39,13 @@ menu "Wi-Fi Provisioning Manager" config WIFI_PROV_KEEP_BLE_ON_AFTER_PROV bool "Keep BT on after provisioning is done" depends on BT_ENABLED + select ESP_PROTOCOMM_KEEP_BLE_ON_AFTER_BLE_STOP config WIFI_PROV_DISCONNECT_AFTER_PROV bool "Terminate connection after provisioning is done" depends on WIFI_PROV_KEEP_BLE_ON_AFTER_PROV default y + select ESP_PROTOCOMM_DISCONNECT_AFTER_BLE_STOP choice WIFI_PROV_STA_SCAN_METHOD bool "Wifi Provisioning Scan Method"