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

Commit 75e0a6e3 authored by Mingguang Xu's avatar Mingguang Xu
Browse files

btaa: HCI ACL/SCO/ISO data packets process

Parse ACL/SCO/ISO packets to get connection handle, match to device address, and attribute them to device-based activities.

Tag: #feature

Bug: 185596854
Bug: 170315554

Test: mmma -j system/bt
Test: manual

BYPASS_LONG_LINES_REASON: consist with gd format

Change-Id: Icb879814ee34700afa35ace1cdca8ff1e8f55fe4
parent 89e6ebaf
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -23,7 +23,7 @@
namespace bluetooth {
namespace activity_attribution {

enum class Activity : uint8_t { UNKNOWN = 0, ADVERTISE, CONNECT, CONTROL, SCAN, HFP, VENDOR };
enum class Activity : uint8_t { UNKNOWN = 0, ACL, ADVERTISE, CONNECT, CONTROL, HFP, ISO, SCAN, VENDOR };
#define CONVERT_ACTIVITY_TO_STR(Activity) std::string(#Activity)

struct BtaaAggregationEntry {
+2 −1
Original line number Diff line number Diff line
@@ -44,6 +44,7 @@ const ModuleFactory ActivityAttribution::Factory = ModuleFactory([]() { return n

static const std::string kBtWakelockName("hal_bluetooth_lock");
static const std::string kBtWakeupReason("hs_uart_wakeup");
static const size_t kHciAclHeaderSize = 4;

struct wakelock_callback : public BnWakelockCallback {
  wakelock_callback(ActivityAttribution* module) : module_(module) {}
@@ -150,7 +151,7 @@ void ActivityAttribution::Capture(const hal::HciPacket& packet, hal::SnoopLogger
    case hal::SnoopLogger::PacketType::ACL:
    case hal::SnoopLogger::PacketType::SCO:
    case hal::SnoopLogger::PacketType::ISO:
      truncate_length = 0;
      truncate_length = kHciAclHeaderSize;
      break;
  }

+42 −0
Original line number Diff line number Diff line
@@ -215,6 +215,45 @@ static void process_event(
  }
}

static void process_acl(
    std::vector<BtaaHciPacket>& btaa_hci_packets,
    packet::PacketView<packet::kLittleEndian>& packet_view,
    uint16_t byte_count) {
  hci::AclView acl = hci::AclView::Create(packet_view);
  auto connection_handle = acl.begin();
  // Connection handle is extracted from the 12 least significant bit.
  uint16_t connection_handle_value = connection_handle.extract<uint16_t>() & 0xfff;
  hci::Address address_value;
  device_parser.match_handle_with_address(connection_handle_value, address_value);
  btaa_hci_packets.push_back(BtaaHciPacket(Activity::ACL, address_value, byte_count));
}

static void process_sco(
    std::vector<BtaaHciPacket>& btaa_hci_packets,
    packet::PacketView<packet::kLittleEndian>& packet_view,
    uint16_t byte_count) {
  hci::ScoView sco = hci::ScoView::Create(packet_view);
  auto connection_handle = sco.begin();
  // Connection handle is extracted from the 12 least significant bit.
  uint16_t connection_handle_value = connection_handle.extract<uint16_t>() & 0xfff;
  hci::Address address_value;
  device_parser.match_handle_with_address(connection_handle_value, address_value);
  btaa_hci_packets.push_back(BtaaHciPacket(Activity::HFP, address_value, byte_count));
}

static void process_iso(
    std::vector<BtaaHciPacket>& btaa_hci_packets,
    packet::PacketView<packet::kLittleEndian>& packet_view,
    uint16_t byte_count) {
  hci::IsoView iso = hci::IsoView::Create(packet_view);
  auto connection_handle = iso.begin();
  // Connection handle is extracted from the 12 least significant bit.
  uint16_t connection_handle_value = connection_handle.extract<uint16_t>() & 0xfff;
  hci::Address address_value;
  device_parser.match_handle_with_address(connection_handle_value, address_value);
  btaa_hci_packets.push_back(BtaaHciPacket(Activity::ISO, address_value, byte_count));
}

std::vector<BtaaHciPacket> HciProcessor::OnHciPacket(
    hal::HciPacket packet, hal::SnoopLogger::PacketType type, uint16_t length) {
  std::vector<BtaaHciPacket> btaa_hci_packets;
@@ -227,10 +266,13 @@ std::vector<BtaaHciPacket> HciProcessor::OnHciPacket(
      process_event(btaa_hci_packets, packet_view, length);
      break;
    case hal::SnoopLogger::PacketType::ACL:
      process_acl(btaa_hci_packets, packet_view, length);
      break;
    case hal::SnoopLogger::PacketType::SCO:
      process_sco(btaa_hci_packets, packet_view, length);
      break;
    case hal::SnoopLogger::PacketType::ISO:
      process_iso(btaa_hci_packets, packet_view, length);
      break;
  }
  return btaa_hci_packets;
+4 −2
Original line number Diff line number Diff line
@@ -26,12 +26,14 @@ class ActivityAttributionCallbacks {
 public:
  enum class Activity : uint8_t {
    UNKNOWN = 0,
    ACL,
    ADVERTISE,
    CONNECT,
    CONTROL,
    SCAN,
    HFP,
    VENDOR
    ISO,
    SCAN,
    VENDOR,
  };

  struct BtaaAggregationEntry {