From 1096731245ac9a56ed5623b6f2dc6a13dc671fa1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Damian=20Kr=C3=B3lik?= <66667989+Damian-Nordic@users.noreply.github.com> Date: Sat, 14 Jan 2023 11:33:10 +0100 Subject: [PATCH] [Zephyr] Return false in unimplemented BLE central methods (#24407) * [zephyr] BLE manager cleanup Remove stale definitions and costly BLE central error logs. Signed-off-by: Damian Krolik * [nrfconnect] Fix build with DFU over SMP Two examples have not been fully updated and they do not compile with DFU over SMP enabled. Signed-off-by: Damian Krolik Signed-off-by: Damian Krolik --- .../nrfconnect/main/AppTask.cpp | 6 ++-- examples/lock-app/nrfconnect/main/AppTask.cpp | 6 ++-- src/platform/Zephyr/BLEManagerImpl.cpp | 34 +++++++------------ src/platform/Zephyr/BLEManagerImpl.h | 9 +---- 4 files changed, 20 insertions(+), 35 deletions(-) diff --git a/examples/all-clusters-app/nrfconnect/main/AppTask.cpp b/examples/all-clusters-app/nrfconnect/main/AppTask.cpp index 5e3dc0adc48163..ea8dcfddc8f535 100644 --- a/examples/all-clusters-app/nrfconnect/main/AppTask.cpp +++ b/examples/all-clusters-app/nrfconnect/main/AppTask.cpp @@ -336,9 +336,9 @@ void AppTask::FunctionTimerEventHandler(const AppEvent & event) void AppTask::RequestSMPAdvertisingStart(void) { AppEvent event; - event.Type = AppEvent::kEventType_StartSMPAdvertising; - event.Handler = [](AppEvent *) { GetDFUOverSMP().StartBLEAdvertising(); }; - sAppTask.PostEvent(&event); + event.Type = AppEventType::StartSMPAdvertising; + event.Handler = [](const AppEvent &) { GetDFUOverSMP().StartBLEAdvertising(); }; + PostEvent(event); } #endif diff --git a/examples/lock-app/nrfconnect/main/AppTask.cpp b/examples/lock-app/nrfconnect/main/AppTask.cpp index 5e1248cfbd8ae4..88b58c1a32fcd8 100644 --- a/examples/lock-app/nrfconnect/main/AppTask.cpp +++ b/examples/lock-app/nrfconnect/main/AppTask.cpp @@ -403,9 +403,9 @@ void AppTask::FunctionTimerEventHandler(const AppEvent & event) void AppTask::RequestSMPAdvertisingStart(void) { AppEvent event; - event.Type = AppEvent::kEventType_StartSMPAdvertising; - event.Handler = [](AppEvent *) { GetDFUOverSMP().StartBLEAdvertising(); }; - sAppTask.PostEvent(&event); + event.Type = AppEventType::StartSMPAdvertising; + event.Handler = [](const AppEvent &) { GetDFUOverSMP().StartBLEAdvertising(); }; + PostEvent(event); } #endif diff --git a/src/platform/Zephyr/BLEManagerImpl.cpp b/src/platform/Zephyr/BLEManagerImpl.cpp index d4639f8ea94aa7..e6b299d37af4e9 100644 --- a/src/platform/Zephyr/BLEManagerImpl.cpp +++ b/src/platform/Zephyr/BLEManagerImpl.cpp @@ -74,7 +74,7 @@ _bt_gatt_ccc CHIPoBLEChar_TX_CCC = BT_GATT_CCC_INITIALIZER(nullptr, BLEManagerIm // clang-format off -struct bt_gatt_attr sChipoBleAttributes[] = { +static bt_gatt_attr sChipoBleAttributes[] = { BT_GATT_PRIMARY_SERVICE(&UUID16_CHIPoBLEService.uuid), BT_GATT_CHARACTERISTIC(&UUID128_CHIPoBLEChar_RX.uuid, BT_GATT_CHRC_WRITE | BT_GATT_CHRC_WRITE_WITHOUT_RESP, @@ -93,7 +93,7 @@ struct bt_gatt_attr sChipoBleAttributes[] = { #endif }; -struct bt_gatt_service sChipoBleService = BT_GATT_SERVICE(sChipoBleAttributes); +static bt_gatt_service sChipoBleService = BT_GATT_SERVICE(sChipoBleAttributes); // clang-format on @@ -344,9 +344,6 @@ CHIP_ERROR BLEManagerImpl::StopAdvertising(void) CHIP_ERROR BLEManagerImpl::_SetAdvertisingEnabled(bool val) { - VerifyOrReturnError(mServiceMode != ConnectivityManager::kCHIPoBLEServiceMode_NotSupported, - CHIP_ERROR_UNSUPPORTED_CHIP_FEATURE); - if (mFlags.Has(Flags::kAdvertisingEnabled) != val) { ChipLogDetail(DeviceLayer, "CHIPoBLE advertising set to %s", val ? "on" : "off"); @@ -385,11 +382,6 @@ CHIP_ERROR BLEManagerImpl::_GetDeviceName(char * buf, size_t bufSize) CHIP_ERROR BLEManagerImpl::_SetDeviceName(const char * deviceName) { - if (mServiceMode == ConnectivityManager::kCHIPoBLEServiceMode_NotSupported) - { - return CHIP_ERROR_UNSUPPORTED_CHIP_FEATURE; - } - ChipLogDetail(DeviceLayer, "Device name set to: %s", deviceName); return MapErrorZephyr(bt_set_name(deviceName)); } @@ -623,14 +615,14 @@ uint16_t BLEManagerImpl::GetMTU(BLE_CONNECTION_OBJECT conId) const bool BLEManagerImpl::SubscribeCharacteristic(BLE_CONNECTION_OBJECT conId, const ChipBleUUID * svcId, const ChipBleUUID * charId) { - ChipLogError(DeviceLayer, "%s: NOT IMPLEMENTED", __PRETTY_FUNCTION__); - return true; + ChipLogDetail(DeviceLayer, "BLE central not implemented"); + return false; } bool BLEManagerImpl::UnsubscribeCharacteristic(BLE_CONNECTION_OBJECT conId, const ChipBleUUID * svcId, const ChipBleUUID * charId) { - ChipLogError(DeviceLayer, "%s: NOT IMPLEMENTED", __PRETTY_FUNCTION__); - return true; + ChipLogDetail(DeviceLayer, "BLE central not implemented"); + return false; } bool BLEManagerImpl::SendIndication(BLE_CONNECTION_OBJECT conId, const ChipBleUUID * svcId, const ChipBleUUID * charId, @@ -667,22 +659,22 @@ bool BLEManagerImpl::SendIndication(BLE_CONNECTION_OBJECT conId, const ChipBleUU bool BLEManagerImpl::SendWriteRequest(BLE_CONNECTION_OBJECT conId, const ChipBleUUID * svcId, const ChipBleUUID * charId, PacketBufferHandle pBuf) { - ChipLogError(DeviceLayer, "%s: NOT IMPLEMENTED", __PRETTY_FUNCTION__); - return true; + ChipLogDetail(DeviceLayer, "BLE central not implemented"); + return false; } bool BLEManagerImpl::SendReadRequest(BLE_CONNECTION_OBJECT conId, const ChipBleUUID * svcId, const ChipBleUUID * charId, PacketBufferHandle pBuf) { - ChipLogError(DeviceLayer, "%s: NOT IMPLEMENTED", __PRETTY_FUNCTION__); - return true; + ChipLogDetail(DeviceLayer, "BLE central not implemented"); + return false; } bool BLEManagerImpl::SendReadResponse(BLE_CONNECTION_OBJECT conId, BLE_READ_REQUEST_CONTEXT requestContext, const ChipBleUUID * svcId, const ChipBleUUID * charId) { - ChipLogError(DeviceLayer, "%s: NOT IMPLEMENTED", __PRETTY_FUNCTION__); - return true; + ChipLogDetail(DeviceLayer, "BLE central not implemented"); + return false; } void BLEManagerImpl::NotifyChipConnectionClosed(BLE_CONNECTION_OBJECT conId) @@ -768,7 +760,7 @@ ssize_t BLEManagerImpl::HandleTXCCCWrite(struct bt_conn * conId, const struct bt return sizeof(value); } -void BLEManagerImpl::HandleTXIndicated(struct bt_conn * conId, IndicationAttrType, uint8_t err) +void BLEManagerImpl::HandleTXIndicated(struct bt_conn * conId, bt_gatt_indicate_params *, uint8_t err) { ChipDeviceEvent event; diff --git a/src/platform/Zephyr/BLEManagerImpl.h b/src/platform/Zephyr/BLEManagerImpl.h index fae4799bda75e3..b87f111460a2ca 100644 --- a/src/platform/Zephyr/BLEManagerImpl.h +++ b/src/platform/Zephyr/BLEManagerImpl.h @@ -49,13 +49,6 @@ class BLEManagerImpl final : public BLEManager, private BleLayer, private BlePla friend BLEManager; private: - // As a result of https://github.com/zephyrproject-rtos/zephyr/issues/29357, BLE indication - // callback parameter type has changed in recent Zephyr revisions. Select the compatible type - // below to support both versions for now. - using IndicationAttrType = - std::conditional_t::value, - bt_gatt_indicate_params *, const bt_gatt_attr *>; - // ===== Members that implement the BLEManager internal interface. CHIP_ERROR _Init(void); @@ -134,7 +127,7 @@ class BLEManagerImpl final : public BLEManager, private BleLayer, private BlePla static void DriveBLEState(intptr_t arg); // Below callbacks run from the system workqueue context and have a limited stack capacity. - static void HandleTXIndicated(bt_conn * conn, IndicationAttrType attr, uint8_t err); + static void HandleTXIndicated(bt_conn * conn, bt_gatt_indicate_params * attr, uint8_t err); static void HandleConnect(bt_conn * conn, uint8_t err); static void HandleDisconnect(bt_conn * conn, uint8_t reason); static void HandleBLEAdvertisementIntervalChange(System::Layer * layer, void * param);