Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for notifications for efr32 #8666

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/include/platform/CHIPDeviceEvent.h
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,7 @@ enum InternalEventTypes
kCHIPoBLEWriteReceived,
kCHIPoBLEIndicateConfirm,
kCHIPoBLEConnectionError,
kCHIPoBLENotifyConfirm
};

static_assert(kEventTypeNotSet == 0, "kEventTypeNotSet must be defined as 0");
Expand Down Expand Up @@ -393,6 +394,10 @@ struct ChipDeviceEvent final
CHIP_ERROR Reason;
} CHIPoBLEConnectionError;
struct
{
BLE_CONNECTION_OBJECT ConId;
} CHIPoBLENotifyConfirm;
struct
{
bool RoleChanged : 1;
bool AddressChanged : 1;
Expand Down
43 changes: 30 additions & 13 deletions src/platform/EFR32/BLEManagerImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ void BLEManagerImpl::bluetoothStackEventHandler(void * p_arg)

if (sl_bt_gatt_server_confirmation == StatusFlags)
{
sInstance.HandleTxConfirmationEvent(bluetooth_evt);
sInstance.HandleTxConfirmationEvent(bluetooth_evt->data.evt_gatt_server_characteristic_status.connection);
}
else if ((bluetooth_evt->data.evt_gatt_server_characteristic_status.characteristic == gattdb_CHIPoBLEChar_Tx) &&
(bluetooth_evt->data.evt_gatt_server_characteristic_status.status_flags == gatt_server_client_config))
Expand Down Expand Up @@ -452,6 +452,12 @@ void BLEManagerImpl::_OnPlatformEvent(const ChipDeviceEvent * event)
}
break;

case DeviceEventType::kCHIPoBLENotifyConfirm: {
ChipLogProgress(DeviceLayer, "_OnPlatformEvent kCHIPoBLENotifyConfirm");
HandleTxConfirmationEvent(event->CHIPoBLENotifyConfirm.ConId);
}
break;

default:
ChipLogProgress(DeviceLayer, "_OnPlatformEvent default: event->Type = %d", event->Type);
break;
Expand Down Expand Up @@ -502,23 +508,31 @@ bool BLEManagerImpl::SendIndication(BLE_CONNECTION_OBJECT conId, const ChipBleUU
sl_status_t ret;
uint16_t cId = (UUIDsMatch(&ChipUUID_CHIPoBLEChar_RX, charId) ? gattdb_CHIPoBLEChar_Rx : gattdb_CHIPoBLEChar_Tx);
uint8_t timerHandle = GetTimerHandle(conId, true);
ChipDeviceEvent event;

VerifyOrExit(((conState != NULL) && (conState->subscribed != 0)), err = CHIP_ERROR_INVALID_ARGUMENT);
VerifyOrExit(timerHandle != kMaxConnections, err = CHIP_ERROR_NO_MEMORY);

// start timer for light indication confirmation. Long delay for spake2 indication
// start timer for light notification confirmation. Long delay for spake2 indication
sl_bt_system_set_soft_timer(TIMER_S_2_TIMERTICK(6), timerHandle, true);

ret = sl_bt_gatt_server_send_indication(conId, cId, (data->DataLength()), data->Start());

ret = sl_bt_gatt_server_send_notification(conId, cId, (data->DataLength()), data->Start());
err = MapBLEError(ret);

if (err == CHIP_NO_ERROR)
{
event.Type = DeviceEventType::kCHIPoBLENotifyConfirm;
event.CHIPoBLENotifyConfirm.ConId = conId;
PlatformMgr().PostEvent(&event);
}

exit:
if (err != CHIP_NO_ERROR)
{
ChipLogError(DeviceLayer, "BLEManagerImpl::SendIndication() failed: %s", ErrorStr(err));
return false;
}

return true;
}

Expand Down Expand Up @@ -558,6 +572,8 @@ CHIP_ERROR BLEManagerImpl::MapBLEError(int bleErr)
return CHIP_ERROR_INVALID_STRING_LENGTH;
case SL_STATUS_INVALID_PARAMETER:
return CHIP_ERROR_INVALID_ARGUMENT;
case SL_STATUS_INVALID_STATE:
return CHIP_ERROR_INCORRECT_STATE;
default:
return ChipError::Encapsulate(ChipError::Range::kPlatform, bleErr + CHIP_DEVICE_CONFIG_EFR32_BLE_ERROR_MIN);
}
Expand Down Expand Up @@ -887,19 +903,20 @@ void BLEManagerImpl::HandleTXCharCCCDWrite(volatile sl_bt_msg_t * evt)
{
CHIP_ERROR err = CHIP_NO_ERROR;
CHIPoBLEConState * bleConnState;
bool indicationsEnabled;
bool isDisabled;
ChipDeviceEvent event;

bleConnState = GetConnectionState(evt->data.evt_gatt_server_user_write_request.connection);

VerifyOrExit(bleConnState != NULL, err = CHIP_ERROR_NO_MEMORY);

// Determine if the client is enabling or disabling indications.
indicationsEnabled = (evt->data.evt_gatt_server_characteristic_status.client_config_flags == gatt_indication);
// Determine if the client is enabling or disabling notification/indication.
isDisabled = (evt->data.evt_gatt_server_characteristic_status.client_config_flags == sl_bt_gatt_disable);

ChipLogProgress(DeviceLayer, "CHIPoBLE %s received", indicationsEnabled ? "subscribe" : "unsubscribe");
ChipLogProgress(DeviceLayer, "HandleTXcharCCCDWrite - Config Flags value : %d",
evt->data.evt_gatt_server_characteristic_status.client_config_flags);
ChipLogProgress(DeviceLayer, "CHIPoBLE %s received", isDisabled ? "unsubscribe" : "subscribe");

if (indicationsEnabled)
if (!isDisabled)
{
// If indications are not already enabled for the connection...
if (!bleConnState->subscribed)
Expand Down Expand Up @@ -959,10 +976,10 @@ void BLEManagerImpl::HandleRXCharWrite(volatile sl_bt_msg_t * evt)
}
}

void BLEManagerImpl::HandleTxConfirmationEvent(volatile sl_bt_msg_t * evt)
void BLEManagerImpl::HandleTxConfirmationEvent(BLE_CONNECTION_OBJECT conId)
{
ChipDeviceEvent event;
uint8_t timerHandle = sInstance.GetTimerHandle(evt->data.evt_gatt_server_characteristic_status.connection);
uint8_t timerHandle = sInstance.GetTimerHandle(conId);

ChipLogProgress(DeviceLayer, "Tx Confirmation received");

Expand All @@ -974,7 +991,7 @@ void BLEManagerImpl::HandleTxConfirmationEvent(volatile sl_bt_msg_t * evt)
}

event.Type = DeviceEventType::kCHIPoBLEIndicateConfirm;
event.CHIPoBLEIndicateConfirm.ConId = evt->data.evt_gatt_server_characteristic_status.connection;
event.CHIPoBLEIndicateConfirm.ConId = conId;
PlatformMgr().PostEvent(&event);
}

Expand Down
2 changes: 1 addition & 1 deletion src/platform/EFR32/BLEManagerImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ class BLEManagerImpl final : public BLEManager, private BleLayer, private BlePla
void HandleWriteEvent(volatile sl_bt_msg_t * evt);
void HandleTXCharCCCDWrite(volatile sl_bt_msg_t * evt);
void HandleRXCharWrite(volatile sl_bt_msg_t * evt);
void HandleTxConfirmationEvent(volatile sl_bt_msg_t * evt);
void HandleTxConfirmationEvent(BLE_CONNECTION_OBJECT conId);
void HandleSoftTimerEvent(volatile sl_bt_msg_t * evt);
bool RemoveConnection(uint8_t connectionHandle);
void AddConnection(uint8_t connectionHandle, uint8_t bondingHandle);
Expand Down
84 changes: 46 additions & 38 deletions src/platform/EFR32/gatt.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,80 +19,88 @@

<!--Custom BLE GATT-->
<gatt gatt_caching="true" generic_attribute_service="true" header="gatt_db.h" name="Custom BLE GATT" out="gatt_db.c" prefix="gattdb_">

<!--Generic Access-->
<service advertise="false" name="Generic Access" requirement="mandatory" sourceId="org.bluetooth.service.generic_access" type="primary" uuid="1800">
<informativeText>Abstract: The generic_access service contains generic information about the device. All available Characteristics are readonly. </informativeText>

<!--Device Name-->
<characteristic id="device_name" name="Device Name" sourceId="org.bluetooth.characteristic.gap.device_name" uuid="2A00">
<characteristic const="false" id="device_name" name="Device Name" sourceId="org.bluetooth.characteristic.gap.device_name" uuid="2A00">
<informativeText/>
<value length="13" type="utf-8" variable_length="false">Empty Example</value>
<properties read="true" read_requirement="optional" write="true" write_requirement="optional"/>
<properties>
<read authenticated="false" bonded="false" encrypted="false"/>
<write authenticated="false" bonded="false" encrypted="false"/>
</properties>
</characteristic>

<!--Appearance-->
<characteristic name="Appearance" sourceId="org.bluetooth.characteristic.gap.appearance" uuid="2A01">
<characteristic const="true" name="Appearance" sourceId="org.bluetooth.characteristic.gap.appearance" uuid="2A01">
<informativeText>Abstract: The external appearance of this device. The values are composed of a category (10-bits) and sub-categories (6-bits). </informativeText>
<value length="2" type="hex" variable_length="false">0000</value>
<properties const="true" const_requirement="optional" read="true" read_requirement="optional"/>
<properties>
<read authenticated="false" bonded="false" encrypted="false"/>
</properties>
</characteristic>
</service>

<!--Device Information-->
<service advertise="false" name="Device Information" requirement="mandatory" sourceId="org.bluetooth.service.device_information" type="primary" uuid="180A">
<informativeText>Abstract: The Device Information Service exposes manufacturer and/or vendor information about a device. Summary: This service exposes manufacturer information about a device. The Device Information Service is instantiated as a Primary Service. Only one instance of the Device Information Service is exposed on a device. </informativeText>

<!--Manufacturer Name String-->
<characteristic name="Manufacturer Name String" sourceId="org.bluetooth.characteristic.manufacturer_name_string" uuid="2A29">
<characteristic const="true" name="Manufacturer Name String" sourceId="org.bluetooth.characteristic.manufacturer_name_string" uuid="2A29">
<informativeText>Abstract: The value of this characteristic is a UTF-8 string representing the name of the manufacturer of the device. </informativeText>
<value length="12" type="utf-8" variable_length="false">Silicon Labs</value>
<properties const="true" const_requirement="optional" read="true" read_requirement="optional"/>
<properties>
<read authenticated="false" bonded="false" encrypted="false"/>
</properties>
</characteristic>

<!--Model Number String-->
<characteristic name="Model Number String" sourceId="org.bluetooth.characteristic.model_number_string" uuid="2A24">
<characteristic const="true" name="Model Number String" sourceId="org.bluetooth.characteristic.model_number_string" uuid="2A24">
<informativeText>Abstract: The value of this characteristic is a UTF-8 string representing the model number assigned by the device vendor. </informativeText>
<value length="10" type="utf-8" variable_length="false">Blue Gecko</value>
<properties const="true" const_requirement="optional" read="true" read_requirement="optional"/>
<properties>
<read authenticated="false" bonded="false" encrypted="false"/>
</properties>
</characteristic>

<!--System ID-->
<characteristic name="System ID" sourceId="org.bluetooth.characteristic.system_id" uuid="2A23">
<characteristic const="true" name="System ID" sourceId="org.bluetooth.characteristic.system_id" uuid="2A23">
<informativeText>Abstract: The SYSTEM ID characteristic consists of a structure with two fields. The first field are the LSOs and the second field contains the MSOs. This is a 64-bit structure which consists of a 40-bit manufacturer-defined identifier concatenated with a 24 bit unique Organizationally Unique Identifier (OUI). The OUI is issued by the IEEE Registration Authority (http://standards.ieee.org/regauth/index.html) and is required to be used in accordance with IEEE Standard 802-2001.6 while the least significant 40 bits are manufacturer defined. If System ID generated based on a Bluetooth Device Address, it is required to be done as follows. System ID and the Bluetooth Device Address have a very similar structure: a Bluetooth Device Address is 48 bits in length and consists of a 24 bit Company Assigned Identifier (manufacturer defined identifier) concatenated with a 24 bit Company Identifier (OUI). In order to encapsulate a Bluetooth Device Address as System ID, the Company Identifier is concatenated with 0xFFFE followed by the Company Assigned Identifier of the Bluetooth Address. For more guidelines related to EUI-64, refer to http://standards.ieee.org/develop/regauth/tut/eui64.pdf. Examples: If the system ID is based of a Bluetooth Device Address with a Company Identifier (OUI) is 0x123456 and the Company Assigned Identifier is 0x9ABCDE, then the System Identifier is required to be 0x123456FFFE9ABCDE. </informativeText>
<value length="6" type="hex" variable_length="false">000102030405</value>
<properties const="true" const_requirement="optional" read="true" read_requirement="optional"/>
<properties>
<read authenticated="false" bonded="false" encrypted="false"/>
</properties>
</characteristic>
</service>

<!--Silicon Labs OTA-->
<service advertise="false" name="Silicon Labs OTA" requirement="mandatory" sourceId="com.silabs.service.ota" type="primary" uuid="1D14D6EE-FD63-4FA1-BFA4-8F47B42119F0">
<informativeText>Abstract: The Silicon Labs OTA Service enables over-the-air firmware update of the device. </informativeText>

<!--Silicon Labs OTA Control-->
<characteristic id="ota_control" name="Silicon Labs OTA Control" sourceId="com.silabs.characteristic.ota_control" uuid="F7BF3564-FB6D-4E53-88A4-5E37E0326063">
<informativeText>Abstract: Silicon Labs OTA Control. </informativeText>
<value length="1" type="user" variable_length="false"/>
<properties write="true" write_requirement="optional"/>
</characteristic>
</service>


<!--CHIPoBLE-->
<service advertise="false" name="CHIPoBLE" requirement="mandatory" sourceId="custom.type" type="primary" uuid="fff6">
<informativeText>Custom service</informativeText>

<!--CHIPoBLEChar_Rx-->
<characteristic id="CHIPoBLEChar_Rx" name="CHIPoBLEChar_Rx" sourceId="custom.type" uuid="18EE2EF5-263D-4559-959F-4F9C429F9D11">
<characteristic const="false" id="CHIPoBLEChar_Rx" name="CHIPoBLEChar_Rx" sourceId="custom.type" uuid="18EE2EF5-263D-4559-959F-4F9C429F9D11">
<informativeText>Custom characteristic</informativeText>
<value length="247" type="hex" variable_length="true">0x00</value>
<properties read="true" read_requirement="optional" write="true" write_requirement="optional"/>
<value length="247" type="hex" variable_length="true">00</value>
<properties>
<read authenticated="false" bonded="false" encrypted="false"/>
<write authenticated="false" bonded="false" encrypted="false"/>
</properties>
</characteristic>

<!--CHIPoBLEChar_Tx-->
<characteristic id="CHIPoBLEChar_Tx" name="CHIPoBLEChar_Tx" sourceId="custom.type" uuid="18EE2EF5-263D-4559-959F-4F9C429F9D12">
<characteristic const="false" id="CHIPoBLEChar_Tx" name="CHIPoBLEChar_Tx" sourceId="custom.type" uuid="18EE2EF5-263D-4559-959F-4F9C429F9D12">
<informativeText>Custom characteristic</informativeText>
<value length="247" type="hex" variable_length="true">0x00</value>
<properties indicate="true" indicate_requirement="optional" read="true" read_requirement="optional" write="true" write_no_response="true" write_no_response_requirement="optional" write_requirement="optional"/>
<value length="247" type="hex" variable_length="true">00</value>
<properties>
<read authenticated="false" bonded="false" encrypted="false"/>
<write authenticated="false" bonded="false" encrypted="false"/>
<write_no_response authenticated="false" bonded="false" encrypted="false"/>
<indicate authenticated="false" bonded="false" encrypted="false"/>
<notify authenticated="false" bonded="false" encrypted="false"/>
</properties>
</characteristic>
</service>
</gatt>
6 changes: 3 additions & 3 deletions src/platform/EFR32/gatt_db.c
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ GATT_DATA(const sli_bt_gattdb_value_t gattdb_attribute_field_26) = { .len = 16,
0x1d,
} };
GATT_DATA(sli_bt_gattdb_attribute_chrvalue_t
gattdb_attribute_field_24) = { .properties = 0x2e,
gattdb_attribute_field_24) = { .properties = 0x3e,
.max_len = 247,
.len = 1,
.data = {
Expand Down Expand Up @@ -352,7 +352,7 @@ GATT_DATA(const sli_bt_gattdb_attribute_t gattdb_attributes_map[]) = {
.caps = 0xffff,
.state = 0x00,
.datatype = 0x05,
.characteristic = { .properties = 0x2e, .char_uuid = 0x8001 } },
.characteristic = { .properties = 0x3e, .char_uuid = 0x8001 } },
{ .handle = 0x19,
.uuid = 0x8001,
.permissions = 0x807,
Expand All @@ -366,7 +366,7 @@ GATT_DATA(const sli_bt_gattdb_attribute_t gattdb_attributes_map[]) = {
.caps = 0xffff,
.state = 0x00,
.datatype = 0x03,
.configdata = { .flags = 0x02, .clientconfig_index = 0x01 } },
.configdata = { .flags = 0x03, .clientconfig_index = 0x01 } },
{ .handle = 0x1b,
.uuid = 0x0000,
.permissions = 0x801,
Expand Down