Skip to content

Commit

Permalink
P6: Added support of BLE GATT Notification instead of GATT Indication…
Browse files Browse the repository at this point in the history
… for C2 GATT Characteristic. It required by Matter spec (section 4.15.3.2. BTP GATT Service): "... the server SHALL exclusively use C2 to respond to BTP handshake requests and send data to the client via GATT ATT_HANDLE_VALUE_NTF PDUs..."
  • Loading branch information
nazar.palamar committed Oct 8, 2021
1 parent 6453262 commit 7416b2a
Showing 1 changed file with 13 additions and 30 deletions.
43 changes: 13 additions & 30 deletions src/platform/P6/BLEManagerImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -254,8 +254,8 @@ void BLEManagerImpl::_OnPlatformEvent(const ChipDeviceEvent * event)
PacketBufferHandle::Adopt(event->CHIPoBLEWriteReceived.Data));
break;

case DeviceEventType::kCHIPoBLEIndicateConfirm:
HandleIndicationConfirmation(event->CHIPoBLEIndicateConfirm.ConId, &CHIP_BLE_SVC_ID, &ChipUUID_CHIPoBLEChar_TX);
case DeviceEventType::kCHIPoBLENotifyConfirm:
HandleIndicationConfirmation(event->CHIPoBLENotifyConfirm.ConId, &CHIP_BLE_SVC_ID, &ChipUUID_CHIPoBLEChar_TX);
break;

case DeviceEventType::kCHIPoBLEConnectionError:
Expand Down Expand Up @@ -342,18 +342,26 @@ bool BLEManagerImpl::SendIndication(BLE_CONNECTION_OBJECT conId, const ChipBleUU
VerifyOrExit(conState != NULL, err = CHIP_ERROR_INVALID_ARGUMENT);

#ifdef BLE_DEBUG
ChipLogDetail(DeviceLayer, "Sending indication for CHIPoBLE TX characteristic (con %u, len %u)", conId, dataLen);
ChipLogDetail(DeviceLayer, "Sending notification for CHIPoBLE TX characteristic (con %u, len %u)", conId, dataLen);
#endif

// Send a indication for the CHIPoBLE TX characteristic to the client containing the supplied data.
gatt_err = wiced_bt_gatt_send_indication((uint16_t) conId, HDLC_CHIP_SERVICE_CHAR_C2_VALUE, dataLen, data->Start());
// Send a notification for the CHIPoBLE TX characteristic to the client containing the supplied data.
gatt_err = wiced_bt_gatt_send_notification((uint16_t) conId, HDLC_CHIP_SERVICE_CHAR_C2_VALUE, dataLen, data->Start());

exit:
if (gatt_err != WICED_BT_GATT_SUCCESS)
{
ChipLogError(DeviceLayer, "BLEManagerImpl::SendIndication() failed: %ld", gatt_err);
return false;
}
else
{
// inform the platform, that notification was sent
ChipDeviceEvent event;
event.Type = DeviceEventType::kCHIPoBLENotifyConfirm;
event.CHIPoBLENotifyConfirm.ConId = conId;
err = PlatformMgr().PostEvent(&event);
}
return err == CHIP_NO_ERROR;
}

Expand Down Expand Up @@ -615,27 +623,6 @@ wiced_bt_gatt_status_t BLEManagerImpl::HandleGattServiceMtuReq(wiced_bt_gatt_att
return WICED_BT_GATT_SUCCESS;
}

/*
* Process GATT Indication Confirm from the client
*/
wiced_bt_gatt_status_t BLEManagerImpl::HandleGattServiceIndCfm(uint16_t conn_id, uint16_t handle)
{
#ifdef BLE_DEBUG
ChipLogDetail(DeviceLayer, "GATT Ind Cfm received con:%04x handle:%d", conn_id, handle);
#endif
if (handle == HDLC_CHIP_SERVICE_CHAR_C2_VALUE)
{
ChipDeviceEvent event;
event.Type = DeviceEventType::kCHIPoBLEIndicateConfirm;
event.CHIPoBLEIndicateConfirm.ConId = conn_id;
if (PlatformMgr().PostEvent(&event) != CHIP_NO_ERROR)
{
return WICED_BT_GATT_INTERNAL_ERROR;
}
}
return WICED_BT_GATT_SUCCESS;
}

/*
* Process GATT attribute requests
*/
Expand All @@ -658,10 +645,6 @@ wiced_bt_gatt_status_t BLEManagerImpl::HandleGattServiceRequestEvent(wiced_bt_ga
result = HandleGattServiceMtuReq(p_request, p_conn);
break;

case GATTS_REQ_TYPE_CONF:
result = HandleGattServiceIndCfm(p_request->conn_id, p_request->data.handle);
break;

default:
break;
}
Expand Down

0 comments on commit 7416b2a

Please sign in to comment.