diff --git a/src/connectivity/bluetooth/core/bt-host/att/BUILD.gn b/src/connectivity/bluetooth/core/bt-host/att/BUILD.gn index 3715f76cb091abaefff7fa8a3574eecff64151e8..0f5100bd803fa0e0ac47661f96a72541f94f7955 100644 --- a/src/connectivity/bluetooth/core/bt-host/att/BUILD.gn +++ b/src/connectivity/bluetooth/core/bt-host/att/BUILD.gn @@ -13,6 +13,8 @@ source_set("definitions") { public_deps = [ "//src/connectivity/bluetooth/core/bt-host/common", + "//src/connectivity/bluetooth/core/bt-host/hci:definitions", + "//src/connectivity/bluetooth/core/bt-host/l2cap:definitions", ] } diff --git a/src/connectivity/bluetooth/core/bt-host/att/att.h b/src/connectivity/bluetooth/core/bt-host/att/att.h index ec9fbfe486784ba76b0452b72070ddc188bed008..46cd5e5d233c7da290304bec4f97314149a0933d 100644 --- a/src/connectivity/bluetooth/core/bt-host/att/att.h +++ b/src/connectivity/bluetooth/core/bt-host/att/att.h @@ -14,6 +14,8 @@ #include "lib/zx/time.h" #include "src/connectivity/bluetooth/core/bt-host/common/uint128.h" +#include "src/connectivity/bluetooth/core/bt-host/hci/hci_constants.h" +#include "src/connectivity/bluetooth/core/bt-host/l2cap/l2cap.h" namespace bt { namespace att { @@ -24,6 +26,8 @@ constexpr uint16_t kLEMinMTU = 23; // v5.0, Vol 3, Part G, 5.1.1 constexpr uint16_t kBREDRMinMTU = 48; +constexpr uint16_t kLEMaxMTU = hci::kMaxLEExtendedDataLength - sizeof(l2cap::BasicHeader); + // The maximum length of an attribute value (v5.0, Vol 3, Part F, 3.2.9). constexpr size_t kMaxAttributeValueLength = 512; diff --git a/src/connectivity/bluetooth/core/bt-host/att/bearer.cc b/src/connectivity/bluetooth/core/bt-host/att/bearer.cc index 8f63e7e35d12007a573b8744720efeb0139f62dd..2ad921c23a033d77ea210ac802a65794f63bdbbc 100644 --- a/src/connectivity/bluetooth/core/bt-host/att/bearer.cc +++ b/src/connectivity/bluetooth/core/bt-host/att/bearer.cc @@ -277,8 +277,8 @@ Bearer::Bearer(fbl::RefPtr<l2cap::Channel> chan) } mtu_ = min_mtu(); - preferred_mtu_ = - std::max(min_mtu(), std::min(chan_->tx_mtu(), chan_->rx_mtu())); + // TODO (BT-854): Dynamically configure preferred MTU value. + preferred_mtu_ = kLEMaxMTU; } Bearer::~Bearer() { diff --git a/src/connectivity/bluetooth/core/bt-host/att/bearer_unittest.cc b/src/connectivity/bluetooth/core/bt-host/att/bearer_unittest.cc index efc0011e689fae5aa2503e3482fc5ab52dffdd81..05308930fac937fc7ffe817d61f0efac93777fb3 100644 --- a/src/connectivity/bluetooth/core/bt-host/att/bearer_unittest.cc +++ b/src/connectivity/bluetooth/core/bt-host/att/bearer_unittest.cc @@ -66,6 +66,10 @@ TEST_F(ATT_BearerTest, CreateFailsToActivate) { EXPECT_FALSE(Bearer::Create(std::move(fake_chan))); } +TEST_F(ATT_BearerTest, CreateUsesLEMaxMTUAsPreferredMTU) { + EXPECT_EQ(kLEMaxMTU, bearer()->preferred_mtu()); +} + TEST_F(ATT_BearerTest, ShutDown) { ASSERT_TRUE(bearer()->is_open()); ASSERT_FALSE(fake_att_chan()->link_error()); diff --git a/src/connectivity/bluetooth/core/bt-host/gatt/server_unittest.cc b/src/connectivity/bluetooth/core/bt-host/gatt/server_unittest.cc index eee49b0fd145933c7dfef0f78546a4cbec0db049..142319b2343c70d257a576153763022d03be6023 100644 --- a/src/connectivity/bluetooth/core/bt-host/gatt/server_unittest.cc +++ b/src/connectivity/bluetooth/core/bt-host/gatt/server_unittest.cc @@ -7,6 +7,7 @@ #include <fbl/macros.h> #include <lib/async/cpp/task.h> +#include "src/connectivity/bluetooth/core/bt-host/att/att.h" #include "src/connectivity/bluetooth/core/bt-host/att/database.h" #include "src/connectivity/bluetooth/core/bt-host/common/test_helpers.h" #include "src/connectivity/bluetooth/core/bt-host/gatt/gatt_defs.h" @@ -87,7 +88,7 @@ TEST_F(GATT_ServerTest, ExchangeMTURequestInvalidPDU) { } TEST_F(GATT_ServerTest, ExchangeMTURequestValueTooSmall) { - const uint16_t kServerMTU = l2cap::kDefaultMTU; + const uint16_t kServerMTU = att::kLEMaxMTU; constexpr uint16_t kClientMTU = 1; // clang-format off @@ -98,7 +99,7 @@ TEST_F(GATT_ServerTest, ExchangeMTURequestValueTooSmall) { const auto kExpected = common::CreateStaticByteBuffer( 0x03, // opcode: exchange MTU response - 0xA0, 0x02 // server rx mtu: |kServerMTU| + 0xF7, 0x00 // server rx mtu: |kServerMTU| ); // clang-format on @@ -111,7 +112,7 @@ TEST_F(GATT_ServerTest, ExchangeMTURequestValueTooSmall) { } TEST_F(GATT_ServerTest, ExchangeMTURequest) { - constexpr uint16_t kServerMTU = l2cap::kDefaultMTU; + constexpr uint16_t kServerMTU = att::kLEMaxMTU; constexpr uint16_t kClientMTU = 0x64; // clang-format off @@ -122,7 +123,7 @@ TEST_F(GATT_ServerTest, ExchangeMTURequest) { const auto kExpected = common::CreateStaticByteBuffer( 0x03, // opcode: exchange MTU response - 0xA0, 0x02 // server rx mtu: |kServerMTU| + 0xF7, 0x00 // server rx mtu: |kServerMTU| ); // clang-format on diff --git a/src/connectivity/bluetooth/core/bt-host/hci/hci_constants.h b/src/connectivity/bluetooth/core/bt-host/hci/hci_constants.h index 041d65e985f0c4dd0051c4207aa669742638cfd4..e2727b98b73f3379d382869d2a2d0c8d97237642 100644 --- a/src/connectivity/bluetooth/core/bt-host/hci/hci_constants.h +++ b/src/connectivity/bluetooth/core/bt-host/hci/hci_constants.h @@ -1147,6 +1147,10 @@ constexpr size_t kMaxLEAdvertisingDataLength = 0x1F; // (31) // command packets. constexpr size_t kMaxLEExtendedAdvertisingDataLength = 251; +// The maximum length of LE data packets when the LE Data Packet Length Extension +// feature is supported. See v5.0, Vol 6, Part B, 4.5.10, Table 4.3. +constexpr size_t kMaxLEExtendedDataLength = 251; + // Maximum value of the Advertising SID subfield in the ADI field of the PDU constexpr uint8_t kLEAdvertsingSIDMax = 0xEF;