Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 5031896e authored by Jakub Pawlowski's avatar Jakub Pawlowski Committed by Gerrit Code Review
Browse files

Merge changes I4d735bc4,Ic5e8c027

* changes:
  eatt: Improve handling incoming EATT connection
  eatt: Fix for the crash on incoming channel creation
parents de81f530 f20be75c
Loading
Loading
Loading
Loading
+25 −12
Original line number Diff line number Diff line
@@ -131,6 +131,12 @@ struct eatt_impl {
                                    &local_coc_cfg))
      return;

    if (!eatt_dev->eatt_tcb_) {
      eatt_dev->eatt_tcb_ =
          gatt_find_tcb_by_addr(eatt_dev->bda_, BT_TRANSPORT_LE);
      CHECK(eatt_dev->eatt_tcb_);
    }

    for (uint16_t cid : lcids) {
      EattChannel* channel = find_eatt_channel_by_cid(bda, cid);
      CHECK(!channel);
@@ -140,8 +146,6 @@ struct eatt_impl {
      eatt_dev->eatt_channels.insert({cid, chan});

      chan->EattChannelSetState(EattChannelState::EATT_CHANNEL_OPENED);

      CHECK(eatt_dev->eatt_tcb_);
      eatt_dev->eatt_tcb_->eatt++;

      LOG(INFO) << __func__ << " Channel connected CID " << loghex(cid);
@@ -567,7 +571,8 @@ struct eatt_impl {
                 << bd_addr;
  }

  void supported_features_cb(const RawAddress& bd_addr, uint8_t features) {
  void supported_features_cb(uint8_t role, const RawAddress& bd_addr,
                             uint8_t features) {
    bool is_eatt_supported = features & BLE_GATT_SVR_SUP_FEAT_EATT_BITMASK;

    LOG(INFO) << __func__ << " " << bd_addr
@@ -575,6 +580,15 @@ struct eatt_impl {
    if (!is_eatt_supported) return;

    eatt_device* eatt_dev = add_eatt_device(bd_addr);

    if (role != HCI_ROLE_CENTRAL) {
      /* TODO For now do nothing, we could run a timer here and start EATT if
       * not started by central */
      LOG(INFO)
          << " EATT Should be connected by the central. Let's wait for it.";
      return;
    }

    connect_eatt(eatt_dev);
  }

@@ -620,19 +634,18 @@ struct eatt_impl {
    LOG(INFO) << __func__ << " device " << bd_addr << " role"
              << (role == HCI_ROLE_CENTRAL ? "central" : "peripheral");

    if (eatt_dev) {
      /* We are reconnecting device we know that support EATT.
       * Just connect CoC
       */
      LOG(INFO) << __func__ << " Known device, connect eCoC";

      if (role != HCI_ROLE_CENTRAL) {
      /* TODO For now do nothing, we could run a timer here and start EATT if
       * not started by central */
        LOG(INFO)
            << " EATT Should be connected by the central. Let's wait for it.";
        return;
      }

    if (eatt_dev) {
      /* We are reconnecting device we know that support EATT.
       * Just connect CoC
       */
      LOG(INFO) << __func__ << " Known device, connect eCoC";
      connect_eatt(eatt_dev);
      return;
    }
@@ -640,7 +653,7 @@ struct eatt_impl {
    /* For new device, first read GATT server supported features. */
    if (gatt_cl_read_sr_supp_feat_req(
            bd_addr, base::BindOnce(&eatt_impl::supported_features_cb,
                                    base::Unretained(this))) == false) {
                                    base::Unretained(this), role)) == false) {
      LOG(INFO) << __func__ << "Eatt is not supported. Checked for device "
                << bd_addr;
    }
+67 −12
Original line number Diff line number Diff line
@@ -110,9 +110,8 @@ class EattTest : public testing::Test {
    ASSERT_TRUE(test_tcb.eatt == 0);
  }

  void DisconnectEattDevice(void) {
    EXPECT_CALL(l2cap_interface_, DisconnectRequest(_))
        .Times(connected_cids_.size());
  void DisconnectEattDevice(std::vector<uint16_t> cids) {
    EXPECT_CALL(l2cap_interface_, DisconnectRequest(_)).Times(cids.size());
    eatt_instance_->Disconnect(test_address);

    ASSERT_TRUE(test_tcb.eatt == 0);
@@ -177,12 +176,68 @@ class EattTest : public testing::Test {

TEST_F(EattTest, ConnectSucceed) {
  ConnectDeviceEattSupported(1);
  DisconnectEattDevice();
  DisconnectEattDevice(connected_cids_);
}

TEST_F(EattTest, IncomingEattConnectionByUnknownDevice) {
  std::vector<uint16_t> incoming_cids{71, 72, 73, 74, 75};

  EXPECT_CALL(l2cap_interface_,
              ConnectCreditBasedRsp(test_address, 1, incoming_cids,
                                    L2CAP_CONN_NO_RESOURCES, _))
      .WillOnce(Return(true));

  l2cap_app_info_.pL2CA_CreditBasedConnectInd_Cb(
      test_address, incoming_cids, BT_PSM_EATT, EATT_MIN_MTU_MPS, 1);
}

TEST_F(EattTest, IncomingEattConnectionByKnownDevice) {
  hci_role_ = HCI_ROLE_PERIPHERAL;
  ON_CALL(gatt_interface_, ClientReadSupportedFeatures)
      .WillByDefault(
          [](const RawAddress& addr,
             base::OnceCallback<void(const RawAddress&, uint8_t)> cb) {
            std::move(cb).Run(addr, BLE_GATT_SVR_SUP_FEAT_EATT_BITMASK);
            return true;
          });
  ON_CALL(gatt_interface_, GetEattSupport)
      .WillByDefault([](const RawAddress& addr) { return true; });

  eatt_instance_->Connect(test_address);
  std::vector<uint16_t> incoming_cids{71, 72, 73, 74, 75};

  EXPECT_CALL(
      l2cap_interface_,
      ConnectCreditBasedRsp(test_address, 1, incoming_cids, L2CAP_CONN_OK, _))
      .WillOnce(Return(true));

  l2cap_app_info_.pL2CA_CreditBasedConnectInd_Cb(
      test_address, incoming_cids, BT_PSM_EATT, EATT_MIN_MTU_MPS, 1);

  DisconnectEattDevice(incoming_cids);

  hci_role_ = HCI_ROLE_CENTRAL;
}

TEST_F(EattTest, ReconnectInitiatedByRemoteSucceed) {
  ConnectDeviceEattSupported(1);
  DisconnectEattDevice(connected_cids_);
  std::vector<uint16_t> incoming_cids{71, 72, 73, 74, 75};

  EXPECT_CALL(
      l2cap_interface_,
      ConnectCreditBasedRsp(test_address, 1, incoming_cids, L2CAP_CONN_OK, _))
      .WillOnce(Return(true));

  l2cap_app_info_.pL2CA_CreditBasedConnectInd_Cb(
      test_address, incoming_cids, BT_PSM_EATT, EATT_MIN_MTU_MPS, 1);

  DisconnectEattDevice(incoming_cids);
}

TEST_F(EattTest, ConnectSucceedMultipleChannels) {
  ConnectDeviceEattSupported(5);
  DisconnectEattDevice();
  DisconnectEattDevice(connected_cids_);
}

TEST_F(EattTest, ConnectFailedEattNotSupported) {
@@ -253,7 +308,7 @@ TEST_F(EattTest, ReconfigAllSucceed) {
    ASSERT_TRUE(channel->rx_mtu_ == new_mtu);
  }

  DisconnectEattDevice();
  DisconnectEattDevice(connected_cids_);
}

TEST_F(EattTest, ReconfigAllFailed) {
@@ -281,7 +336,7 @@ TEST_F(EattTest, ReconfigAllFailed) {
    ASSERT_TRUE(channel->rx_mtu_ != new_mtu);
  }

  DisconnectEattDevice();
  DisconnectEattDevice(connected_cids_);
}

TEST_F(EattTest, ReconfigSingleSucceed) {
@@ -308,7 +363,7 @@ TEST_F(EattTest, ReconfigSingleSucceed) {
  ASSERT_TRUE(channel->state_ == EattChannelState::EATT_CHANNEL_OPENED);
  ASSERT_TRUE(channel->rx_mtu_ == new_mtu);

  DisconnectEattDevice();
  DisconnectEattDevice(connected_cids_);
}

TEST_F(EattTest, ReconfigSingleFailed) {
@@ -336,7 +391,7 @@ TEST_F(EattTest, ReconfigSingleFailed) {
  ASSERT_TRUE(channel->state_ == EattChannelState::EATT_CHANNEL_OPENED);
  ASSERT_TRUE(channel->rx_mtu_ != new_mtu);

  DisconnectEattDevice();
  DisconnectEattDevice(connected_cids_);
}

TEST_F(EattTest, ReconfigPeerSucceed) {
@@ -355,7 +410,7 @@ TEST_F(EattTest, ReconfigPeerSucceed) {
    ASSERT_TRUE(channel->tx_mtu_ == new_mtu);
  }

  DisconnectEattDevice();
  DisconnectEattDevice(connected_cids_);
}

TEST_F(EattTest, ReconfigPeerFailed) {
@@ -375,12 +430,12 @@ TEST_F(EattTest, ReconfigPeerFailed) {
    ASSERT_TRUE(channel->tx_mtu_ != new_mtu);
  }

  DisconnectEattDevice();
  DisconnectEattDevice(connected_cids_);
}

TEST_F(EattTest, DoubleDisconnect) {
  ConnectDeviceEattSupported(1);
  DisconnectEattDevice();
  DisconnectEattDevice(connected_cids_);

  /* Force second disconnect */
  eatt_instance_->Disconnect(test_address);