Skip to content

Commit

Permalink
[btp] align code to the specification (#10177)
Browse files Browse the repository at this point in the history
  • Loading branch information
LuDuda authored and pull[bot] committed Oct 5, 2021
1 parent 8cd3b77 commit a72d82b
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ class BluetoothManager : BleCallback {
wrappedCallback.onServicesDiscovered(gatt, status)

Log.i("$TAG|onServicesDiscovered", "Services Discovered")
gatt?.requestMtu(131);
gatt?.requestMtu(247);
}

override fun onMtuChanged(gatt: BluetoothGatt?, mtu: Int, status: Int) {
Expand Down
23 changes: 5 additions & 18 deletions src/ble/BLEEndPoint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1112,18 +1112,13 @@ CHIP_ERROR BLEEndPoint::HandleCapabilitiesRequestReceived(PacketBufferHandle &&
CHIP_BLE_TRANSPORT_PROTOCOL_MIN_SUPPORTED_VERSION, CHIP_BLE_TRANSPORT_PROTOCOL_MAX_SUPPORTED_VERSION);
mState = kState_Aborting;
}
else if ((resp.mSelectedProtocolVersion == kBleTransportProtocolVersion_V1) ||
(resp.mSelectedProtocolVersion == kBleTransportProtocolVersion_V2))
else
{
// Set Rx and Tx fragment sizes to the same value
mBtpEngine.SetRxFragmentSize(resp.mFragmentSize);
mBtpEngine.SetTxFragmentSize(resp.mFragmentSize);
}
else // resp.SelectedProtocolVersion >= kBleTransportProtocolVersion_V3
{
// This is the peripheral, so set Rx fragment size, and leave Tx at default
mBtpEngine.SetRxFragmentSize(resp.mFragmentSize);
}

ChipLogProgress(Ble, "using BTP fragment sizes rx %d / tx %d.", mBtpEngine.GetRxFragmentSize(), mBtpEngine.GetTxFragmentSize());

ReturnErrorOnFailure(resp.Encode(responseBuf));
Expand Down Expand Up @@ -1158,17 +1153,9 @@ CHIP_ERROR BLEEndPoint::HandleCapabilitiesResponseReceived(PacketBufferHandle &&
// Set fragment size as minimum of (reported ATT MTU, BTP characteristic size)
resp.mFragmentSize = chip::min(resp.mFragmentSize, BtpEngine::sMaxFragmentSize);

if ((resp.mSelectedProtocolVersion == kBleTransportProtocolVersion_V1) ||
(resp.mSelectedProtocolVersion == kBleTransportProtocolVersion_V2))
{
mBtpEngine.SetRxFragmentSize(resp.mFragmentSize);
mBtpEngine.SetTxFragmentSize(resp.mFragmentSize);
}
else // resp.SelectedProtocolVersion >= kBleTransportProtocolVersion_V3
{
// This is the central, so set Tx fragement size, and leave Rx at default.
mBtpEngine.SetTxFragmentSize(resp.mFragmentSize);
}
mBtpEngine.SetRxFragmentSize(resp.mFragmentSize);
mBtpEngine.SetTxFragmentSize(resp.mFragmentSize);

ChipLogProgress(Ble, "using BTP fragment sizes rx %d / tx %d.", mBtpEngine.GetRxFragmentSize(), mBtpEngine.GetTxFragmentSize());

// Select local and remote max receive window size based on local resources available for both incoming indications
Expand Down
8 changes: 4 additions & 4 deletions src/ble/BleConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@
*
*/
#ifndef BLE_MAX_RECEIVE_WINDOW_SIZE
#define BLE_MAX_RECEIVE_WINDOW_SIZE 3
#define BLE_MAX_RECEIVE_WINDOW_SIZE 6
#endif

#if (BLE_MAX_RECEIVE_WINDOW_SIZE < 3)
Expand All @@ -180,7 +180,7 @@
*
*/
#ifndef BLE_CONFIG_ERROR_MIN
#define BLE_CONFIG_ERROR_MIN 6000
#define BLE_CONFIG_ERROR_MIN 6000
#endif // BLE_CONFIG_ERROR_MIN

/**
Expand All @@ -191,7 +191,7 @@
*
*/
#ifndef BLE_CONFIG_ERROR_MAX
#define BLE_CONFIG_ERROR_MAX 6999
#define BLE_CONFIG_ERROR_MAX 6999
#endif // BLE_CONFIG_ERROR_MAX

/**
Expand All @@ -203,7 +203,7 @@
*
*/
#ifndef BLE_CONFIG_ERROR
#define BLE_CONFIG_ERROR(e) (BLE_CONFIG_ERROR_MIN + (e))
#define BLE_CONFIG_ERROR(e) (BLE_CONFIG_ERROR_MIN + (e))
#endif // BLE_CONFIG_ERROR

// clang-format on
Expand Down
4 changes: 2 additions & 2 deletions src/ble/BleLayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@
#include <lib/support/logging/CHIPLogging.h>

// Magic values expected in first 2 bytes of valid BLE transport capabilities request or response:
#define CAPABILITIES_MSG_CHECK_BYTE_1 'n'
#define CAPABILITIES_MSG_CHECK_BYTE_2 'l'
#define CAPABILITIES_MSG_CHECK_BYTE_1 0b01100101
#define CAPABILITIES_MSG_CHECK_BYTE_2 0b01101100

namespace chip {
namespace Ble {
Expand Down
8 changes: 3 additions & 5 deletions src/ble/BleLayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@ namespace Ble {
*/
#define NUM_SUPPORTED_PROTOCOL_VERSIONS 8
/// Version(s) of the CHIP BLE Transport Protocol that this stack supports.
#define CHIP_BLE_TRANSPORT_PROTOCOL_MIN_SUPPORTED_VERSION kBleTransportProtocolVersion_V2
#define CHIP_BLE_TRANSPORT_PROTOCOL_MAX_SUPPORTED_VERSION kBleTransportProtocolVersion_V3
#define CHIP_BLE_TRANSPORT_PROTOCOL_MIN_SUPPORTED_VERSION kBleTransportProtocolVersion_V4
#define CHIP_BLE_TRANSPORT_PROTOCOL_MAX_SUPPORTED_VERSION kBleTransportProtocolVersion_V4

/// Forward declarations.
class BleLayer;
Expand All @@ -88,9 +88,7 @@ class BLEEndPoint;
typedef enum
{
kBleTransportProtocolVersion_None = 0,
kBleTransportProtocolVersion_V1 = 1, // Prototype BTP version without ACKs or flow-control.
kBleTransportProtocolVersion_V2 = 2, // First BTP version with ACKs and flow-control.
kBleTransportProtocolVersion_V3 = 3 // First BTP version with asymetric fragement sizes.
kBleTransportProtocolVersion_V4 = 4 // BTP as defined by CHIP v1.0
} BleTransportProtocolVersion;

constexpr size_t kCapabilitiesRequestMagicnumLength = 2;
Expand Down
2 changes: 1 addition & 1 deletion src/ble/BtpEngine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ static void PrintBufDebug(const System::PacketBufferHandle & buf)
}

const uint16_t BtpEngine::sDefaultFragmentSize = 20; // 23-byte minimum ATT_MTU - 3 bytes for ATT operation header
const uint16_t BtpEngine::sMaxFragmentSize = 128; // Size of write and indication characteristics
const uint16_t BtpEngine::sMaxFragmentSize = 244; // Maximum size of BTP segment

CHIP_ERROR BtpEngine::Init(void * an_app_state, bool expect_first_ack)
{
Expand Down

0 comments on commit a72d82b

Please sign in to comment.