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

Commit 93f242ce authored by Chienyuan's avatar Chienyuan
Browse files

gd: Handle data status for extended advertising report

Tag: #gd-refactor
Bug: 177044452
Test: gd/cert/run --host
Change-Id: I8e04ea0cb1b8df795fdd4287a56262ac211c4f16
parent 5271ac83
Loading
Loading
Loading
Loading
+1 −2
Original line number Diff line number Diff line
@@ -26,7 +26,6 @@
#include "hci/facade/le_scanning_manager_facade.grpc.pb.h"
#include "hci/facade/le_scanning_manager_facade.h"
#include "hci/facade/le_scanning_manager_facade.pb.h"
#include "hci/le_report.h"
#include "os/log.h"
#include "packet/raw_builder.h"

@@ -72,7 +71,7 @@ class LeScanningManagerFacadeService : public LeScanningManagerFacade::Service,
      int8_t tx_power,
      int8_t rssi,
      uint16_t periodic_advertising_interval,
      std::vector<GapData> advertising_data) {
      std::vector<uint8_t> advertising_data) {
    LeReportMsg le_report_msg;
    std::vector<LeExtendedAdvertisingReport> advertisements;
    LeExtendedAdvertisingReport le_extended_advertising_report;
+1 −1
Original line number Diff line number Diff line
@@ -4629,7 +4629,7 @@ struct LeExtendedAdvertisingReport {
  direct_address_type : DirectAdvertisingAddressType,
  direct_address : Address,
  _size_(advertising_data) : 8,
  advertising_data : GapData[],
  advertising_data : 8[],
}

packet LeExtendedAdvertisingReport : LeMetaEvent (subevent_code = EXTENDED_ADVERTISING_REPORT) {

system/gd/hci/le_report.h

deleted100644 → 0
+0 −105
Original line number Diff line number Diff line
/*
 * Copyright 2019 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
#pragma once

#include <memory>

#include "hci/hci_packets.h"

namespace bluetooth::hci {

class LeReport {
 public:
  explicit LeReport(const LeAdvertisingReport& advertisement)
      : report_type_(ReportType::ADVERTISING_EVENT),
        advertising_event_type_(advertisement.event_type_),
        address_(advertisement.address_),
        address_type_(static_cast<DirectAdvertisingAddressType>(advertisement.address_type_)),
        rssi_(advertisement.rssi_),
        gap_data_(advertisement.advertising_data_) {}
  explicit LeReport(const LeDirectedAdvertisingReport& advertisement)
      : report_type_(ReportType::DIRECTED_ADVERTISING_EVENT),
        address_(advertisement.address_),
        address_type_(advertisement.address_type_),
        rssi_(advertisement.rssi_) {}
  explicit LeReport(const LeExtendedAdvertisingReport& advertisement)
      : report_type_(ReportType::EXTENDED_ADVERTISING_EVENT),
        address_(advertisement.address_),
        address_type_(advertisement.address_type_),
        rssi_(advertisement.rssi_),
        gap_data_(advertisement.advertising_data_) {}
  virtual ~LeReport() = default;

  enum class ReportType {
    ADVERTISING_EVENT = 1,
    DIRECTED_ADVERTISING_EVENT = 2,
    EXTENDED_ADVERTISING_EVENT = 3,
  };
  const ReportType report_type_;

  ReportType GetReportType() const {
    return report_type_;
  }

  // Advertising Event
  const AdvertisingEventType advertising_event_type_{};
  const Address address_{};
  const DirectAdvertisingAddressType address_type_{};
  const int8_t rssi_;
  const std::vector<GapData> gap_data_{};
};

class DirectedLeReport : public LeReport {
 public:
  explicit DirectedLeReport(const LeDirectedAdvertisingReport& advertisement)
      : LeReport(advertisement), direct_address_type_(advertisement.address_type_),
        direct_address_(advertisement.direct_address_) {}
  explicit DirectedLeReport(const LeExtendedAdvertisingReport& advertisement)
      : LeReport(advertisement), direct_address_type_(advertisement.address_type_),
        direct_address_(advertisement.direct_address_) {}

  const DirectAdvertisingAddressType direct_address_type_{};
  const Address direct_address_{};
};

class ExtendedLeReport : public DirectedLeReport {
 public:
  explicit ExtendedLeReport(const LeExtendedAdvertisingReport& advertisement)
      : DirectedLeReport(advertisement),
        connectable_(advertisement.connectable_),
        scannable_(advertisement.scannable_),
        directed_(advertisement.directed_),
        scan_response_(advertisement.scan_response_),
        legacy_(advertisement.legacy_),
        complete_(advertisement.data_status_ == DataStatus::COMPLETE),
        truncated_(advertisement.data_status_ == DataStatus::TRUNCATED),
        primary_phy_(static_cast<uint8_t>(advertisement.primary_phy_)),
        secondary_phy_(static_cast<uint8_t>(advertisement.secondary_phy_)),
        tx_power_(advertisement.tx_power_) {}

  // Extended
  bool connectable_;
  bool scannable_;
  bool directed_;
  bool scan_response_;
  bool legacy_;
  bool complete_;
  bool truncated_;
  uint8_t primary_phy_;
  uint8_t secondary_phy_;
  int8_t tx_power_;
};
}  // namespace bluetooth::hci
 No newline at end of file
+19 −8
Original line number Diff line number Diff line
@@ -54,7 +54,7 @@ struct Scanner {

class AdvertisingCache {
 public:
  const std::vector<GapData>& Set(const AddressWithType& address_with_type, std::vector<GapData> data) {
  const std::vector<uint8_t>& Set(const AddressWithType& address_with_type, std::vector<uint8_t> data) {
    auto it = Find(address_with_type);
    if (it != items.end()) {
      it->data = std::move(data);
@@ -76,7 +76,7 @@ class AdvertisingCache {
    return true;
  }

  const std::vector<GapData>& Append(const AddressWithType& address_with_type, std::vector<GapData> data) {
  const std::vector<uint8_t>& Append(const AddressWithType& address_with_type, std::vector<uint8_t> data) {
    auto it = Find(address_with_type);
    if (it != items.end()) {
      it->data.insert(it->data.end(), data.begin(), data.end());
@@ -105,9 +105,9 @@ class AdvertisingCache {

  struct Item {
    AddressWithType address_with_type;
    std::vector<GapData> data;
    std::vector<uint8_t> data;

    Item(const AddressWithType& address_with_type, std::vector<GapData> data)
    Item(const AddressWithType& address_with_type, std::vector<uint8_t> data)
        : address_with_type(address_with_type), data(data) {}
  };

@@ -237,6 +237,13 @@ struct LeScanningManager::impl : public bluetooth::hci::LeAddressManagerCallback
          return;
      }

      std::vector<uint8_t> advertising_data = {};
      for (auto gap_data : report.advertising_data_) {
        advertising_data.push_back((uint8_t)gap_data.size() - 1);
        advertising_data.push_back((uint8_t)gap_data.data_type_);
        advertising_data.insert(advertising_data.end(), gap_data.data_.begin(), gap_data.data_.end());
      }

      process_advertising_package_content(
          extended_event_type,
          (uint8_t)report.address_type_,
@@ -247,7 +254,7 @@ struct LeScanningManager::impl : public bluetooth::hci::LeAddressManagerCallback
          kTxPowerInformationNotPresent,
          report.rssi_,
          kNotPeriodicAdvertisement,
          report.advertising_data_);
          advertising_data);
    }
  }

@@ -313,7 +320,7 @@ struct LeScanningManager::impl : public bluetooth::hci::LeAddressManagerCallback
      int8_t tx_power,
      int8_t rssi,
      uint16_t periodic_advertising_interval,
      std::vector<GapData> advertising_data) {
      std::vector<uint8_t> advertising_data) {
    bool is_scannable = event_type & (1 << kScannableBit);
    bool is_scan_response = event_type & (1 << kScanResponseBit);
    bool is_legacy = event_type & (1 << kLegacyBit);
@@ -326,10 +333,14 @@ struct LeScanningManager::impl : public bluetooth::hci::LeAddressManagerCallback

    bool is_start = is_legacy && is_scannable && !is_scan_response;

    std::vector<GapData> const& adv_data = is_start ? advertising_cache_.Set(address_with_type, advertising_data)
    std::vector<uint8_t> const& adv_data = is_start ? advertising_cache_.Set(address_with_type, advertising_data)
                                                    : advertising_cache_.Append(address_with_type, advertising_data);

    // TODO: handle data status
    uint8_t data_status = event_type >> kDataStatusBits;
    if (data_status == (uint8_t)DataStatus::CONTINUING) {
      // Waiting for whole data
      return;
    }

    if (is_scannable && !is_scan_response) {
      // Waiting for scan response
+1 −2
Original line number Diff line number Diff line
@@ -19,7 +19,6 @@

#include "common/callback.h"
#include "hci/hci_packets.h"
#include "hci/le_report.h"
#include "hci/uuid.h"
#include "module.h"

@@ -49,7 +48,7 @@ class ScanningCallback {
      int8_t tx_power,
      int8_t rssi,
      uint16_t periodic_advertising_interval,
      std::vector<GapData> advertising_data) = 0;
      std::vector<uint8_t> advertising_data) = 0;
  virtual void OnTrackAdvFoundLost() = 0;
  virtual void OnBatchScanReports(
      int client_if, int status, int report_format, int num_records, std::vector<uint8_t> data) = 0;
Loading