[bt][host] Hardcode att bearer preferred mtu

BT-841 #done
TEST=1. manually check that Bluetooth cast setup works
     2. fx run-test bluetooth-tests -t bt-host-unittests

Change-Id: Ic5889243cbad7577598af2b16d7977576c45aa1e
diff --git a/src/connectivity/bluetooth/core/bt-host/att/BUILD.gn b/src/connectivity/bluetooth/core/bt-host/att/BUILD.gn
index 3715f76..0f5100b 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 @@
 
   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 ec9fbfe..46cd5e5 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 @@
 // 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 8f63e7e..2ad921c 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 @@
   }
 
   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 efc0011..0530893 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 @@
   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 eee49b0..142319b 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, 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 @@
 
   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, 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 @@
 
   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 041d65e..e2727b9 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 @@
 // 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;