@@ -133,11 +133,8 @@ CHIP_ERROR BLEEndPoint::StartConnect()
133
133
// Add reference to message fragment for duration of platform's GATT write attempt. CHIP retains partial
134
134
// ownership of message fragment's packet buffer, since this is the same buffer as that of the whole message, just
135
135
// with a fragmenter-modified payload offset and data length, by a Retain() on the handle when calling this function.
136
- if (!SendWrite (buf.Retain ()))
137
- {
138
- err = BLE_ERROR_GATT_WRITE_FAILED;
139
- ExitNow ();
140
- }
136
+ err = SendWrite (buf.Retain ());
137
+ SuccessOrExit (err);
141
138
142
139
// Free request buffer on write confirmation. Stash a reference to it in mSendQueue, which we don't use anyway
143
140
// until the connection has been set up.
@@ -213,13 +210,13 @@ void BLEEndPoint::HandleSubscribeReceived()
213
210
// Add reference to message fragment for duration of platform's GATT indication attempt. CHIP retains partial
214
211
// ownership of message fragment's packet buffer, since this is the same buffer as that of the whole message, just
215
212
// with a fragmenter-modified payload offset and data length.
216
- if (!SendIndication (mSendQueue .Retain ()))
213
+ err = SendIndication (mSendQueue .Retain ());
214
+ if (err != CHIP_NO_ERROR)
217
215
{
218
216
// Ensure transmit queue is empty and set to NULL.
219
217
mSendQueue = nullptr ;
220
218
221
219
ChipLogError (Ble, " cap resp ind failed" );
222
- err = BLE_ERROR_GATT_INDICATE_FAILED;
223
220
ExitNow ();
224
221
}
225
222
@@ -389,9 +386,10 @@ void BLEEndPoint::FinalizeClose(uint8_t oldState, uint8_t flags, CHIP_ERROR err)
389
386
// Indicate close of chipConnection to peripheral via GATT unsubscribe. Keep end point allocated until
390
387
// unsubscribe completes or times out, so platform doesn't close underlying BLE connection before
391
388
// we're really sure the unsubscribe request has been sent.
392
- if (!mBle ->mPlatformDelegate ->UnsubscribeCharacteristic (mConnObj , &CHIP_BLE_SVC_ID, &CHIP_BLE_CHAR_2_UUID))
389
+ err = mBle ->mPlatformDelegate ->UnsubscribeCharacteristic (mConnObj , &CHIP_BLE_SVC_ID, &CHIP_BLE_CHAR_2_UUID);
390
+ if (err != CHIP_NO_ERROR)
393
391
{
394
- ChipLogError (Ble, " BtpEngine unsub failed" );
392
+ ChipLogError (Ble, " BtpEngine unsubscribe failed % " CHIP_ERROR_FORMAT, err. Format () );
395
393
396
394
// If unsubscribe fails, release BLE connection and free end point immediately.
397
395
Free ();
@@ -568,31 +566,20 @@ CHIP_ERROR BLEEndPoint::SendCharacteristic(PacketBufferHandle && buf)
568
566
569
567
if (mRole == kBleRole_Central )
570
568
{
571
- if (!SendWrite (std::move (buf)))
572
- {
573
- err = BLE_ERROR_GATT_WRITE_FAILED;
574
- }
575
- else
576
- {
577
- // Write succeeded, so shrink remote receive window counter by 1.
578
- mRemoteReceiveWindowSize = static_cast <SequenceNumber_t>(mRemoteReceiveWindowSize - 1 );
579
- ChipLogDebugBleEndPoint (Ble, " decremented remote rx window, new size = %u" , mRemoteReceiveWindowSize );
580
- }
569
+ SuccessOrExit (err = SendWrite (std::move (buf)));
570
+ // Write succeeded, so shrink remote receive window counter by 1.
571
+ mRemoteReceiveWindowSize = static_cast <SequenceNumber_t>(mRemoteReceiveWindowSize - 1 );
572
+ ChipLogDebugBleEndPoint (Ble, " decremented remote rx window, new size = %u" , mRemoteReceiveWindowSize );
581
573
}
582
574
else // (mRole == kBleRole_Peripheral), verified on Init
583
575
{
584
- if (!SendIndication (std::move (buf)))
585
- {
586
- err = BLE_ERROR_GATT_INDICATE_FAILED;
587
- }
588
- else
589
- {
590
- // Indication succeeded, so shrink remote receive window counter by 1.
591
- mRemoteReceiveWindowSize = static_cast <SequenceNumber_t>(mRemoteReceiveWindowSize - 1 );
592
- ChipLogDebugBleEndPoint (Ble, " decremented remote rx window, new size = %u" , mRemoteReceiveWindowSize );
593
- }
576
+ SuccessOrExit (err = SendIndication (std::move (buf)));
577
+ // Indication succeeded, so shrink remote receive window counter by 1.
578
+ mRemoteReceiveWindowSize = static_cast <SequenceNumber_t>(mRemoteReceiveWindowSize - 1 );
579
+ ChipLogDebugBleEndPoint (Ble, " decremented remote rx window, new size = %u" , mRemoteReceiveWindowSize );
594
580
}
595
581
582
+ exit :
596
583
return err;
597
584
}
598
585
@@ -750,8 +737,8 @@ CHIP_ERROR BLEEndPoint::HandleHandshakeConfirmationReceived()
750
737
{
751
738
// Subscribe to characteristic which peripheral will use to send indications. Prompts peripheral to send
752
739
// BLE transport capabilities indication.
753
- VerifyOrExit ( mBle ->mPlatformDelegate ->SubscribeCharacteristic (mConnObj , &CHIP_BLE_SVC_ID, &CHIP_BLE_CHAR_2_UUID),
754
- err = BLE_ERROR_GATT_SUBSCRIBE_FAILED );
740
+ err = mBle ->mPlatformDelegate ->SubscribeCharacteristic (mConnObj , &CHIP_BLE_SVC_ID, &CHIP_BLE_CHAR_2_UUID);
741
+ SuccessOrExit ( err);
755
742
756
743
// We just sent a GATT subscribe request, so make sure to attempt unsubscribe on close.
757
744
mConnStateFlags .Set (ConnectionStateFlag::kDidBeginSubscribe );
@@ -1309,18 +1296,25 @@ CHIP_ERROR BLEEndPoint::Receive(PacketBufferHandle && data)
1309
1296
return err;
1310
1297
}
1311
1298
1312
- bool BLEEndPoint::SendWrite (PacketBufferHandle && buf)
1299
+ CHIP_ERROR BLEEndPoint::SendWrite (PacketBufferHandle && buf)
1313
1300
{
1314
1301
mConnStateFlags .Set (ConnectionStateFlag::kGattOperationInFlight );
1315
1302
1316
- return mBle ->mPlatformDelegate ->SendWriteRequest (mConnObj , &CHIP_BLE_SVC_ID, &CHIP_BLE_CHAR_1_UUID, std::move (buf));
1303
+ auto err = mBle ->mPlatformDelegate ->SendWriteRequest (mConnObj , &CHIP_BLE_SVC_ID, &CHIP_BLE_CHAR_1_UUID, std::move (buf));
1304
+ VerifyOrReturnError (err == CHIP_NO_ERROR, err,
1305
+ ChipLogError (Ble, " Send write request failed: %" CHIP_ERROR_FORMAT, err.Format ()));
1306
+
1307
+ return err;
1317
1308
}
1318
1309
1319
- bool BLEEndPoint::SendIndication (PacketBufferHandle && buf)
1310
+ CHIP_ERROR BLEEndPoint::SendIndication (PacketBufferHandle && buf)
1320
1311
{
1321
1312
mConnStateFlags .Set (ConnectionStateFlag::kGattOperationInFlight );
1322
1313
1323
- return mBle ->mPlatformDelegate ->SendIndication (mConnObj , &CHIP_BLE_SVC_ID, &CHIP_BLE_CHAR_2_UUID, std::move (buf));
1314
+ auto err = mBle ->mPlatformDelegate ->SendIndication (mConnObj , &CHIP_BLE_SVC_ID, &CHIP_BLE_CHAR_2_UUID, std::move (buf));
1315
+ VerifyOrReturnError (err == CHIP_NO_ERROR, err, ChipLogError (Ble, " Send indication failed: %" CHIP_ERROR_FORMAT, err.Format ()));
1316
+
1317
+ return err;
1324
1318
}
1325
1319
1326
1320
CHIP_ERROR BLEEndPoint::StartConnectTimer ()
0 commit comments