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

Commit b60e80ea authored by Myles Watson's avatar Myles Watson
Browse files

test_vendor: Use BtAddress instead of vectors



Change-Id: I229f2a4f93a9219a502960e6d91f514738f3b3c8
Signed-off-by: default avatarMyles Watson <mylesgw@google.com>
parent e2906ffc
Loading
Loading
Loading
Loading
+4 −4
Original line number Diff line number Diff line
@@ -26,6 +26,7 @@ using std::vector;
#include "async_manager.h"
#include "base/json/json_value_converter.h"
#include "base/time/time.h"
#include "bt_address.h"
#include "command_packet.h"
#include "hci_transport.h"
#include "test_channel_transport.h"
@@ -87,8 +88,7 @@ class DualModeController {
      return num_sco_data_packets_;
    }

    // Specification Version 4.2, Volume 2, Part E, Section 7.4.6
    const vector<uint8_t>& GetBdAddress() const { return bd_address_; }
    const BtAddress& GetAddress() const { return address_; }

    // Specification Version 4.2, Volume 2, Part E, Section 7.4.8
    const vector<uint8_t>& GetSupportedCodecs() const {
@@ -148,7 +148,7 @@ class DualModeController {
    vector<uint8_t> local_supported_commands_;
    std::string local_name_;
    vector<uint64_t> local_extended_features_;
    vector<uint8_t> bd_address_;
    BtAddress address_;

    uint16_t le_data_packet_length_;
    uint8_t num_le_data_packets_;
@@ -528,7 +528,7 @@ class DualModeController {

  vector<uint8_t> le_event_mask_;

  vector<uint8_t> le_random_address_;
  BtAddress le_random_address_;

  uint8_t le_scan_type_;
  uint16_t le_scan_interval_;
+5 −4
Original line number Diff line number Diff line
@@ -23,6 +23,7 @@
using std::vector;

#include "base/logging.h"
#include "bt_address.h"
#include "packet.h"

namespace test_vendor_lib {
@@ -92,7 +93,7 @@ class EventPacket : public Packet {

  // Bluetooth Core Specification Version 4.2, Volume 2, Part E, Section 7.4.6
  static std::unique_ptr<EventPacket> CreateCommandCompleteReadBdAddr(
      const uint8_t status, const vector<uint8_t>& bd_addr);
      const uint8_t status, const BtAddress& bt_address);

  // Bluetooth Core Specification Version 4.2, Volume 2, Part E, Section 7.4.8
  static std::unique_ptr<EventPacket>
@@ -109,19 +110,19 @@ class EventPacket : public Packet {
  };

  static std::unique_ptr<EventPacket> CreateInquiryResultEvent(
      const vector<uint8_t>& bd_address,
      const BtAddress& bt_address,
      const PageScanRepetitionMode page_scan_repetition_mode,
      const uint32_t class_of_device,
      const uint16_t clock_offset);

  void AddInquiryResult(const vector<uint8_t>& bd_address,
  void AddInquiryResult(const BtAddress& bt_address,
                        const PageScanRepetitionMode page_scan_repetition_mode,
                        const uint32_t class_of_device,
                        const uint16_t clock_offset);

  // Bluetooth Core Specification Version 4.2, Volume 2, Part E, Section 7.7.38
  static std::unique_ptr<EventPacket> CreateExtendedInquiryResultEvent(
      const vector<uint8_t>& bd_address,
      const BtAddress& bt_address,
      const PageScanRepetitionMode page_scan_repetition_mode,
      const uint32_t class_of_device,
      const uint16_t clock_offset,
+5 −0
Original line number Diff line number Diff line
@@ -20,6 +20,7 @@
#include <vector>
using std::vector;

#include "bt_address.h"
#include "hci/include/hci_hal.h"

namespace test_vendor_lib {
@@ -79,6 +80,10 @@ class Packet {
    return AddPayloadOctets(8, value);
  }

  // Add |address| to the payload.  Return true if:
  // - the new size of the payload is still < |kMaxPacketOctets|
  bool AddPayloadBtAddress(const BtAddress& address);

 protected:
  // Constructs an empty packet of type |type| and header |header|
  Packet(serial_data_type_t type, vector<uint8_t> header);
+10 −5
Original line number Diff line number Diff line
@@ -348,7 +348,7 @@ void DualModeController::HciReadBdAddr(
    UNUSED_ATTR const vector<uint8_t>& args) {
  std::unique_ptr<EventPacket> command_complete =
      EventPacket::CreateCommandCompleteReadBdAddr(kSuccessStatus,
                                                   properties_.GetBdAddress());
                                                   properties_.GetAddress());
  send_event_(std::move(command_complete));
}

@@ -497,6 +497,8 @@ void DualModeController::HciInquiry(const vector<uint8_t>& args) {
      EventPacket::kR0;
  const uint32_t kClassOfDevice = 0x030201;
  const uint16_t kClockOffset = 513;
  BtAddress other_addr;
  other_addr.FromVector(kOtherDeviceBdAddress);

  LogCommand("Inquiry");
  state_ = kInquiry;
@@ -504,7 +506,7 @@ void DualModeController::HciInquiry(const vector<uint8_t>& args) {
  switch (inquiry_mode_) {
    case (kStandardInquiry): {
      std::unique_ptr<EventPacket> inquiry_result_evt =
          EventPacket::CreateInquiryResultEvent(kOtherDeviceBdAddress,
          EventPacket::CreateInquiryResultEvent(other_addr,
                                                kPageScanRepetitionMode,
                                                kClassOfDevice,
                                                kClockOffset);
@@ -527,7 +529,7 @@ void DualModeController::HciInquiry(const vector<uint8_t>& args) {

      uint8_t rssi = static_cast<uint8_t>(-20);
      send_event_(
          EventPacket::CreateExtendedInquiryResultEvent(kOtherDeviceBdAddress,
          EventPacket::CreateExtendedInquiryResultEvent(other_addr,
                                                        kPageScanRepetitionMode,
                                                        kClassOfDevice,
                                                        kClockOffset,
@@ -596,7 +598,10 @@ void DualModeController::HciLeReadLocalSupportedFeatures(

void DualModeController::HciLeSetRandomAddress(const vector<uint8_t>& args) {
  LogCommand("LE SetRandomAddress");
  le_random_address_ = args;
  CHECK(args.size() == 7);
  vector<uint8_t> new_addr = {
      args[1], args[2], args[3], args[4], args[5], args[6]};
  CHECK(le_random_address_.FromVector(new_addr));
  SendCommandCompleteSuccess(HCI_BLE_WRITE_RANDOM_ADDR);
}

@@ -714,7 +719,7 @@ DualModeController::Properties::Properties(const std::string& file_name)

  local_extended_features_ = {0xffffffffffffffff, 0x7};

  bd_address_ = {1, 2, 3, 4, 5, 6};
  CHECK(address_.FromString("01:02:03:04:05:06"));
  local_name_ = "DefaultName";

  supported_codecs_ = {1};
+8 −8
Original line number Diff line number Diff line
@@ -170,12 +170,12 @@ std::unique_ptr<EventPacket> EventPacket::CreateCommandCompleteReadBufferSize(

// Bluetooth Core Specification Version 4.2, Volume 2, Part E, Section 7.4.6
std::unique_ptr<EventPacket> EventPacket::CreateCommandCompleteReadBdAddr(
    const uint8_t status, const vector<uint8_t>& bd_addr) {
    const uint8_t status, const BtAddress& address) {
  std::unique_ptr<EventPacket> evt_ptr =
      EventPacket::CreateCommandCompleteOnlyStatusEvent(HCI_READ_BD_ADDR,
                                                        status);

  CHECK(evt_ptr->AddPayloadOctets(6, bd_addr));
  CHECK(evt_ptr->AddPayloadBtAddress(address));

  return evt_ptr;
}
@@ -198,7 +198,7 @@ EventPacket::CreateCommandCompleteReadLocalSupportedCodecs(
}

std::unique_ptr<EventPacket> EventPacket::CreateInquiryResultEvent(
    const vector<uint8_t>& bd_address,
    const BtAddress& address,
    const PageScanRepetitionMode page_scan_repetition_mode,
    const uint32_t class_of_device,
    const uint16_t clock_offset) {
@@ -207,7 +207,7 @@ std::unique_ptr<EventPacket> EventPacket::CreateInquiryResultEvent(

  CHECK(evt_ptr->AddPayloadOctets1(1));  // Start with a single response

  CHECK(evt_ptr->AddPayloadOctets(6, bd_address));
  CHECK(evt_ptr->AddPayloadBtAddress(address));
  CHECK(evt_ptr->AddPayloadOctets1(page_scan_repetition_mode));
  CHECK(evt_ptr->AddPayloadOctets2(kReservedZero));
  CHECK(evt_ptr->AddPayloadOctets3(class_of_device));
@@ -218,7 +218,7 @@ std::unique_ptr<EventPacket> EventPacket::CreateInquiryResultEvent(
}

void EventPacket::AddInquiryResult(
    const vector<uint8_t>& bd_address,
    const BtAddress& address,
    const PageScanRepetitionMode page_scan_repetition_mode,
    const uint32_t class_of_device,
    const uint16_t clock_offset) {
@@ -226,7 +226,7 @@ void EventPacket::AddInquiryResult(

  CHECK(IncrementPayloadCounter(1));  // Increment the number of responses

  CHECK(AddPayloadOctets(6, bd_address));
  CHECK(AddPayloadBtAddress(address));
  CHECK(AddPayloadOctets1(page_scan_repetition_mode));
  CHECK(AddPayloadOctets2(kReservedZero));
  CHECK(AddPayloadOctets3(class_of_device));
@@ -235,7 +235,7 @@ void EventPacket::AddInquiryResult(
}

std::unique_ptr<EventPacket> EventPacket::CreateExtendedInquiryResultEvent(
    const vector<uint8_t>& bd_address,
    const BtAddress& address,
    const PageScanRepetitionMode page_scan_repetition_mode,
    const uint32_t class_of_device,
    const uint16_t clock_offset,
@@ -246,7 +246,7 @@ std::unique_ptr<EventPacket> EventPacket::CreateExtendedInquiryResultEvent(

  CHECK(evt_ptr->AddPayloadOctets1(1));  // Always contains a single response

  CHECK(evt_ptr->AddPayloadOctets(6, bd_address));
  CHECK(evt_ptr->AddPayloadBtAddress(address));
  CHECK(evt_ptr->AddPayloadOctets1(page_scan_repetition_mode));
  CHECK(evt_ptr->AddPayloadOctets1(kReservedZero));
  CHECK(evt_ptr->AddPayloadOctets3(class_of_device));
Loading