OSDN Git Service

RootCanal: Support LeReadRemoteFeatures
authorMyles Watson <mylesgw@google.com>
Fri, 19 Feb 2021 23:02:28 +0000 (15:02 -0800)
committerMyles Watson <mylesgw@google.com>
Fri, 19 Feb 2021 23:03:35 +0000 (15:03 -0800)
Bug: 180748274
Test: cert/run LeAclManagerTest
Tag: #root-canal
Change-Id: I453ace5a55170e58fd70b128d703b331d57ef219

vendor_libs/test_vendor_lib/model/controller/link_layer_controller.cc
vendor_libs/test_vendor_lib/model/controller/link_layer_controller.h
vendor_libs/test_vendor_lib/packets/link_layer_packets.pdl

index 31377a2..6934624 100644 (file)
@@ -68,6 +68,10 @@ ErrorCode LinkLayerController::SendCommandToRemoteByAddress(
   Address local_address = properties_.GetAddress();
 
   switch (opcode) {
+    case (OpCode::LE_READ_REMOTE_FEATURES):
+      SendLinkLayerPacket(model::packets::LeReadRemoteFeaturesBuilder::Create(
+          local_address, remote));
+      break;
     case (OpCode::REMOTE_NAME_REQUEST):
       // LMP features get requested with remote name requests.
       SendLinkLayerPacket(model::packets::ReadRemoteLmpFeaturesBuilder::Create(
@@ -258,6 +262,12 @@ void LinkLayerController::IncomingPacket(
     case model::packets::PacketType::LE_ENCRYPT_CONNECTION_RESPONSE:
       IncomingLeEncryptConnectionResponse(incoming);
       break;
+    case (model::packets::PacketType::LE_READ_REMOTE_FEATURES):
+      IncomingLeReadRemoteFeatures(incoming);
+      break;
+    case (model::packets::PacketType::LE_READ_REMOTE_FEATURES_RESPONSE):
+      IncomingLeReadRemoteFeaturesResponse(incoming);
+      break;
     case model::packets::PacketType::LE_SCAN:
       // TODO: Check Advertising flags and see if we are scannable.
       IncomingLeScanPacket(incoming);
@@ -1262,6 +1272,41 @@ void LinkLayerController::IncomingLeEncryptConnectionResponse(
   }
 }
 
+void LinkLayerController::IncomingLeReadRemoteFeatures(
+    model::packets::LinkLayerPacketView incoming) {
+  uint16_t handle =
+      connections_.GetHandleOnlyAddress(incoming.GetSourceAddress());
+  ErrorCode status = ErrorCode::SUCCESS;
+  if (handle == kReservedHandle) {
+    LOG_INFO("@%s: Unknown connection @%s",
+             incoming.GetDestinationAddress().ToString().c_str(),
+             incoming.GetSourceAddress().ToString().c_str());
+  }
+  SendLinkLayerPacket(
+      model::packets::LeReadRemoteFeaturesResponseBuilder::Create(
+          incoming.GetDestinationAddress(), incoming.GetSourceAddress(),
+          properties_.GetLeSupportedFeatures(), static_cast<uint8_t>(status)));
+}
+
+void LinkLayerController::IncomingLeReadRemoteFeaturesResponse(
+    model::packets::LinkLayerPacketView incoming) {
+  uint16_t handle =
+      connections_.GetHandleOnlyAddress(incoming.GetSourceAddress());
+  ErrorCode status = ErrorCode::SUCCESS;
+  auto response =
+      model::packets::LeReadRemoteFeaturesResponseView::Create(incoming);
+  if (handle == kReservedHandle) {
+    LOG_INFO("@%s: Unknown connection @%s",
+             incoming.GetDestinationAddress().ToString().c_str(),
+             incoming.GetSourceAddress().ToString().c_str());
+    status = ErrorCode::UNKNOWN_CONNECTION;
+  } else {
+    status = static_cast<ErrorCode>(response.GetStatus());
+  }
+  send_event_(bluetooth::hci::LeReadRemoteFeaturesCompleteBuilder::Create(
+      status, handle, response.GetFeatures()));
+}
+
 void LinkLayerController::IncomingLeScanPacket(
     model::packets::LinkLayerPacketView incoming) {
   for (auto& advertiser : advertisers_) {
index 789f85a..b31e849 100644 (file)
@@ -362,6 +362,9 @@ class LinkLayerController {
   void IncomingLeEncryptConnection(model::packets::LinkLayerPacketView packet);
   void IncomingLeEncryptConnectionResponse(
       model::packets::LinkLayerPacketView packet);
+  void IncomingLeReadRemoteFeatures(model::packets::LinkLayerPacketView packet);
+  void IncomingLeReadRemoteFeaturesResponse(
+      model::packets::LinkLayerPacketView packet);
   void IncomingLeScanPacket(model::packets::LinkLayerPacketView packet);
   void IncomingLeScanResponsePacket(model::packets::LinkLayerPacketView packet);
   void IncomingPagePacket(model::packets::LinkLayerPacketView packet);
index 0b10c59..af03848 100644 (file)
@@ -48,6 +48,8 @@ enum PacketType : 8 {
     KEYPRESS_NOTIFICATION = 0x29,
     PIN_REQUEST = 0x2A,
     PIN_RESPONSE = 0x2B,
+    LE_READ_REMOTE_FEATURES = 0x2C,
+    LE_READ_REMOTE_FEATURES_RESPONSE = 0x2D,
 }
 
 packet LinkLayerPacket {
@@ -350,3 +352,11 @@ packet PinResponse : LinkLayerPacket (type = PIN_RESPONSE) {
   _reserved_ : 3,
   pin_code : 8[], // string parameter, first octet first
 }
+
+packet LeReadRemoteFeatures : LinkLayerPacket (type = LE_READ_REMOTE_FEATURES) {
+}
+
+packet LeReadRemoteFeaturesResponse : LinkLayerPacket (type = LE_READ_REMOTE_FEATURES_RESPONSE) {
+  features : 64,
+  status : 8,
+}