From ac8a4b3f1ec0323ba8dd995593c225bd0a33a155 Mon Sep 17 00:00:00 2001 From: Nazar Palamar <46566584+npal-cy@users.noreply.github.com> Date: Wed, 27 Oct 2021 16:43:09 +0300 Subject: [PATCH] =?UTF-8?q?P6:=20Added=20support=20of=20BLE=20GATT=20Notif?= =?UTF-8?q?ication=20instead=20of=20GATT=20Indication=E2=80=A6=20(#10336)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * P6: Added support of BLE GATT Notification instead of GATT Indication 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..." * Update src/platform/P6/BLEManagerImpl.cpp Co-authored-by: Matt Smith Co-authored-by: nazar.palamar Co-authored-by: Justin Wood Co-authored-by: Matt Smith --- src/platform/P6/BLEManagerImpl.cpp | 45 ++++++++++-------------------- 1 file changed, 14 insertions(+), 31 deletions(-) diff --git a/src/platform/P6/BLEManagerImpl.cpp b/src/platform/P6/BLEManagerImpl.cpp index 5d28ec216217f8..69620b24543e65 100644 --- a/src/platform/P6/BLEManagerImpl.cpp +++ b/src/platform/P6/BLEManagerImpl.cpp @@ -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: @@ -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); + ChipLogError(DeviceLayer, "BLEManagerImpl::SendNotification() failed: %ld", gatt_err); return false; } + else + { + // Post an event to the CHIP queue. + ChipDeviceEvent event; + event.Type = DeviceEventType::kCHIPoBLENotifyConfirm; + event.CHIPoBLENotifyConfirm.ConId = conId; + err = PlatformMgr().PostEvent(&event); + } return err == CHIP_NO_ERROR; } @@ -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 */ @@ -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; }