diff --git a/config/esp32/components/chip/CMakeLists.txt b/config/esp32/components/chip/CMakeLists.txt index a88839a5565fee..927c5ddeaa21f4 100644 --- a/config/esp32/components/chip/CMakeLists.txt +++ b/config/esp32/components/chip/CMakeLists.txt @@ -155,6 +155,10 @@ if ((CONFIG_BT_ENABLED) AND (CONFIG_ENABLE_CHIPOBLE)) endif() endif() +if (CONFIG_ENABLE_ESP32_BLE_CONTROLLER) + chip_gn_arg_append("chip_enable_ble_controller" "true") +endif() + if (CONFIG_ENABLE_MATTER_OVER_THREAD) chip_gn_arg_append("chip_enable_openthread" "true") else() diff --git a/config/esp32/components/chip/Kconfig b/config/esp32/components/chip/Kconfig index 077331b16cb3ef..dc3b03b07ac555 100644 --- a/config/esp32/components/chip/Kconfig +++ b/config/esp32/components/chip/Kconfig @@ -917,13 +917,6 @@ menu "CHIP Device Layer" help Enable esp32 as a BLE Commissioner. - config ENABLE_BOTH_COMMISSIONER_AND_COMMISSIONEE - bool "Enable Commissionee and Commissioner mode" - default n - depends on ENABLE_ESP32_BLE_Controller - help - Enable including commissioner code (CHIPDeviceController.cpp) in the commissionee (Server.cpp) code. - endmenu endmenu diff --git a/src/platform/ESP32/BLEManagerImpl.h b/src/platform/ESP32/BLEManagerImpl.h index 71766eaf0c7e8a..d47010e84d5afd 100644 --- a/src/platform/ESP32/BLEManagerImpl.h +++ b/src/platform/ESP32/BLEManagerImpl.h @@ -186,6 +186,7 @@ class BLEManagerImpl final : public BLEManager, #if CONFIG_ENABLE_ESP32_BLE_CONTROLLER void NewConnection(chip::Ble::BleLayer * bleLayer, void * appState, const SetupDiscriminator & connDiscriminator) override; + void NewConnection(chip::Ble::BleLayer * bleLayer, void * appState, BLE_CONNECTION_OBJECT connObj) override{}; CHIP_ERROR CancelConnection() override; // ===== Members that implement virtual methods on ChipDeviceScannerDelegate diff --git a/src/platform/ESP32/BUILD.gn b/src/platform/ESP32/BUILD.gn index 9718bebbc70edb..0e751e7f1455ae 100644 --- a/src/platform/ESP32/BUILD.gn +++ b/src/platform/ESP32/BUILD.gn @@ -27,6 +27,7 @@ declare_args() { chip_enable_chipoble = true chip_bt_nimble_enabled = false chip_bt_bluedroid_enabled = false + chip_enable_ble_controller = false chip_use_secure_cert_dac_provider = false } @@ -90,20 +91,22 @@ static_library("ESP32") { } if (chip_bt_nimble_enabled) { - sources += [ - "nimble/BLEManagerImpl.cpp", - "nimble/ChipDeviceScanner.cpp", - "nimble/blecent.h", - "nimble/misc.c", - "nimble/peer.c", - ] + sources += [ "nimble/BLEManagerImpl.cpp" ] + if (chip_enable_ble_controller) { + sources += [ + "nimble/ChipDeviceScanner.cpp", + "nimble/blecent.h", + "nimble/misc.c", + "nimble/peer.c", + ] + } } if (chip_bt_bluedroid_enabled) { - sources += [ - "bluedroid/BLEManagerImpl.cpp", - "bluedroid/ChipDeviceScanner.cpp", - ] + sources += [ "bluedroid/BLEManagerImpl.cpp" ] + if (chip_enable_ble_controller) { + sources += [ "bluedroid/ChipDeviceScanner.cpp" ] + } } if (chip_enable_wifi) { diff --git a/src/platform/ESP32/CHIPDevicePlatformConfig.h b/src/platform/ESP32/CHIPDevicePlatformConfig.h index 757af45869a7dd..5bee6b221919c2 100644 --- a/src/platform/ESP32/CHIPDevicePlatformConfig.h +++ b/src/platform/ESP32/CHIPDevicePlatformConfig.h @@ -97,4 +97,4 @@ #define CHIP_DEVICE_CONFIG_CHIP_KVS_NAMESPACE_PARTITION CONFIG_CHIP_KVS_NAMESPACE_PARTITION_LABEL #define CHIP_DEVICE_CONFIG_ENABLE_DEVICE_INSTANCE_INFO_PROVIDER CONFIG_ENABLE_ESP32_DEVICE_INSTANCE_INFO_PROVIDER #define CHIP_DEVICE_CONFIG_DISCOVERY_TIMEOUT_SECS CONFIG_CHIP_DISCOVERY_TIMEOUT_SECS -#define CHIP_DEVICE_CONFIG_ENABLE_BOTH_COMMISSIONER_AND_COMMISSIONEE CONFIG_ENABLE_BOTH_COMMISSIONER_AND_COMMISSIONEE +#define CHIP_DEVICE_CONFIG_ENABLE_BOTH_COMMISSIONER_AND_COMMISSIONEE CONFIG_ENABLE_ESP32_BLE_CONTROLLER diff --git a/src/platform/ESP32/nimble/ChipDeviceScanner.cpp b/src/platform/ESP32/nimble/ChipDeviceScanner.cpp index 5bf90bae136f60..4e01340558503f 100644 --- a/src/platform/ESP32/nimble/ChipDeviceScanner.cpp +++ b/src/platform/ESP32/nimble/ChipDeviceScanner.cpp @@ -15,8 +15,6 @@ * limitations under the License. */ -#if CONFIG_ENABLE_ESP32_BLE_CONTROLLER - #include "blecent.h" #include #include @@ -153,4 +151,3 @@ CHIP_ERROR ChipDeviceScanner::StopScan() } // namespace Internal } // namespace DeviceLayer } // namespace chip -#endif // CONFIG_ENABLE_ESP32_BLE_CONTROLLER diff --git a/src/platform/ESP32/nimble/blecent.h b/src/platform/ESP32/nimble/blecent.h index d61eb50bc0fc9d..8ff73e2c4ab919 100644 --- a/src/platform/ESP32/nimble/blecent.h +++ b/src/platform/ESP32/nimble/blecent.h @@ -34,7 +34,6 @@ * under the License. */ #pragma once -#if CONFIG_ENABLE_ESP32_BLE_CONTROLLER #include #ifdef __cplusplus @@ -107,4 +106,3 @@ struct peer * peer_find(uint16_t conn_handle); #ifdef __cplusplus } #endif -#endif // CONFIG_ENABLE_ESP32_BLE_CONTROLLER diff --git a/src/platform/ESP32/nimble/misc.c b/src/platform/ESP32/nimble/misc.c index 2c887dc6918756..8fdd0d20528928 100644 --- a/src/platform/ESP32/nimble/misc.c +++ b/src/platform/ESP32/nimble/misc.c @@ -16,7 +16,6 @@ * specific language governing permissions and limitations * under the License. */ -#if CONFIG_ENABLE_ESP32_BLE_CONTROLLER #include "blecent.h" #include "host/ble_hs.h" #include "host/ble_uuid.h" @@ -216,4 +215,3 @@ void print_adv_fields(const struct ble_hs_adv_fields * fields) MODLOG_DFLT(DEBUG, "\n"); } } -#endif // CONFIG_ENABLE_ESP32_BLE_CONTROLLER diff --git a/src/platform/ESP32/nimble/peer.c b/src/platform/ESP32/nimble/peer.c index 0dbf54475019c6..154e0b23991b2d 100644 --- a/src/platform/ESP32/nimble/peer.c +++ b/src/platform/ESP32/nimble/peer.c @@ -17,8 +17,6 @@ * under the License. */ -#if CONFIG_ENABLE_ESP32_BLE_CONTROLLER - #include "blecent.h" #include "host/ble_hs.h" #include @@ -259,7 +257,8 @@ uint16_t chr_end_handle(const struct peer_svc * svc, const struct peer_chr * chr next_chr = SLIST_NEXT(chr, next); if (next_chr != NULL) { - return next_chr->chr.def_handle - 1; + int result = next_chr->chr.def_handle - 1; + return (uint16_t) result; } else { @@ -763,56 +762,56 @@ int peer_init(int max_peers, int max_svcs, int max_chrs, int max_dscs) /* Free memory first in case this function gets called more than once. */ peer_free_mem(); - peer_mem = malloc(OS_MEMPOOL_BYTES(max_peers, sizeof(struct peer))); + peer_mem = malloc(OS_MEMPOOL_BYTES((uint16_t) max_peers, sizeof(struct peer))); if (peer_mem == NULL) { rc = BLE_HS_ENOMEM; goto err; } - rc = os_mempool_init(&peer_pool, max_peers, sizeof(struct peer), peer_mem, "peer_pool"); + rc = os_mempool_init(&peer_pool, (uint16_t) max_peers, sizeof(struct peer), peer_mem, "peer_pool"); if (rc != 0) { rc = BLE_HS_EOS; goto err; } - peer_svc_mem = malloc(OS_MEMPOOL_BYTES(max_svcs, sizeof(struct peer_svc))); + peer_svc_mem = malloc(OS_MEMPOOL_BYTES((uint16_t) max_svcs, sizeof(struct peer_svc))); if (peer_svc_mem == NULL) { rc = BLE_HS_ENOMEM; goto err; } - rc = os_mempool_init(&peer_svc_pool, max_svcs, sizeof(struct peer_svc), peer_svc_mem, "peer_svc_pool"); + rc = os_mempool_init(&peer_svc_pool, (uint16_t) max_svcs, sizeof(struct peer_svc), peer_svc_mem, "peer_svc_pool"); if (rc != 0) { rc = BLE_HS_EOS; goto err; } - peer_chr_mem = malloc(OS_MEMPOOL_BYTES(max_chrs, sizeof(struct peer_chr))); + peer_chr_mem = malloc(OS_MEMPOOL_BYTES((uint16_t) max_chrs, sizeof(struct peer_chr))); if (peer_chr_mem == NULL) { rc = BLE_HS_ENOMEM; goto err; } - rc = os_mempool_init(&peer_chr_pool, max_chrs, sizeof(struct peer_chr), peer_chr_mem, "peer_chr_pool"); + rc = os_mempool_init(&peer_chr_pool, (uint16_t) max_chrs, sizeof(struct peer_chr), peer_chr_mem, "peer_chr_pool"); if (rc != 0) { rc = BLE_HS_EOS; goto err; } - peer_dsc_mem = malloc(OS_MEMPOOL_BYTES(max_dscs, sizeof(struct peer_dsc))); + peer_dsc_mem = malloc(OS_MEMPOOL_BYTES((uint16_t) max_dscs, sizeof(struct peer_dsc))); if (peer_dsc_mem == NULL) { rc = BLE_HS_ENOMEM; goto err; } - rc = os_mempool_init(&peer_dsc_pool, max_dscs, sizeof(struct peer_dsc), peer_dsc_mem, "peer_dsc_pool"); + rc = os_mempool_init(&peer_dsc_pool, (uint16_t) max_dscs, sizeof(struct peer_dsc), peer_dsc_mem, "peer_dsc_pool"); if (rc != 0) { rc = BLE_HS_EOS; @@ -825,4 +824,3 @@ int peer_init(int max_peers, int max_svcs, int max_chrs, int max_dscs) peer_free_mem(); return rc; } -#endif