Skip to content

Commit

Permalink
[Zephyr] Return false in unimplemented BLE central methods (#24407)
Browse files Browse the repository at this point in the history
* [zephyr] BLE manager cleanup

Remove stale definitions and costly BLE central error logs.

Signed-off-by: Damian Krolik <[email protected]>

* [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 <[email protected]>

Signed-off-by: Damian Krolik <[email protected]>
  • Loading branch information
Damian-Nordic authored and pull[bot] committed Apr 13, 2023
1 parent f60ce24 commit 2288690
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 35 deletions.
6 changes: 3 additions & 3 deletions examples/all-clusters-app/nrfconnect/main/AppTask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
6 changes: 3 additions & 3 deletions examples/lock-app/nrfconnect/main/AppTask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
34 changes: 13 additions & 21 deletions src/platform/Zephyr/BLEManagerImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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

Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -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));
}
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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;

Expand Down
9 changes: 1 addition & 8 deletions src/platform/Zephyr/BLEManagerImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::is_same<bt_gatt_indicate_func_t, void (*)(bt_conn *, bt_gatt_indicate_params *, uint8_t)>::value,
bt_gatt_indicate_params *, const bt_gatt_attr *>;

// ===== Members that implement the BLEManager internal interface.

CHIP_ERROR _Init(void);
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 2288690

Please sign in to comment.