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

Commit a1da5801 authored by android-build-team Robot's avatar android-build-team Robot
Browse files

Snap for 5945950 from 9ad24a5e to rvc-release

Change-Id: Icf6049c44d118b4a963cbfaf8bc7bb5b7cf22a2f
parents ed00fdc8 9ad24a5e
Loading
Loading
Loading
Loading
+22 −0
Original line number Diff line number Diff line
@@ -163,7 +163,29 @@ static int uhid_read_event(btif_hh_device_t* p_dev) {
        APPL_TRACE_ERROR("%s: UHID_FEATURE: Invalid report type = %d", __func__,
                         ev.u.feature.rtype);
      break;
    case UHID_SET_REPORT:
      if (ret < (ssize_t)(sizeof(ev.type) + sizeof(ev.u.set_report))) {
          APPL_TRACE_ERROR("%s: Invalid size read from uhid-dev: %zd < %zu",
                           __func__, ret, sizeof(ev.type) + sizeof(ev.u.set_report));
            return -EFAULT;
        }

        APPL_TRACE_DEBUG("UHID_SET_REPORT: Report type = %d, report_size = %d"
                          , ev.u.set_report.rtype, ev.u.set_report.size);

        if (ev.u.set_report.rtype == UHID_FEATURE_REPORT)
            btif_hh_setreport(p_dev, BTHH_FEATURE_REPORT,
                              ev.u.set_report.size, ev.u.set_report.data);
        else if (ev.u.set_report.rtype == UHID_OUTPUT_REPORT)
            btif_hh_setreport(p_dev, BTHH_OUTPUT_REPORT,
                              ev.u.set_report.size, ev.u.set_report.data);
        else if(ev.u.set_report.rtype == UHID_INPUT_REPORT)
            btif_hh_setreport(p_dev, BTHH_INPUT_REPORT,
                              ev.u.set_report.size, ev.u.set_report.data);
        else
            APPL_TRACE_ERROR("%s:UHID_SET_REPORT: Invalid Report type = %d"
                          , __func__, ev.u.set_report.rtype);
        break;
    default:
      APPL_TRACE_DEBUG("Invalid event from uhid-dev: %u\n", ev.type);
  }
+10 −2
Original line number Diff line number Diff line
@@ -729,7 +729,11 @@ packet InquiryCancelComplete : CommandComplete (command_op_code = INQUIRY_CANCEL
}

packet PeriodicInquiryMode : DiscoveryCommand (op_code = PERIODIC_INQUIRY_MODE) {
  _payload_,  // placeholder (unimplemented)
  max_period_length : 16, // Range 0x0003 to 0xffff (times 1.28s)
  min_period_length : 16, // Range 0x0002 to 0xfffe (times 1.28s)
  lap : Lap,
  inquiry_length : 8, // 0x1 - 0x30 (times 1.28s)
  num_responses : 8, // 0x00 unlimited
}

packet PeriodicInquiryModeComplete : CommandComplete (command_op_code = PERIODIC_INQUIRY_MODE) {
@@ -1446,7 +1450,11 @@ packet ReadPageTimeoutComplete : CommandComplete (command_op_code = READ_PAGE_TI
}

packet WritePageTimeout : DiscoveryCommand (op_code = WRITE_PAGE_TIMEOUT) {
  _payload_,  // placeholder (unimplemented)
  page_timeout : 16,
}

packet WritePageTimeoutComplete : CommandComplete (command_op_code = WRITE_PAGE_TIMEOUT) {
  status : ErrorCode,
}

enum ScanEnable : 8 {
+67 −0
Original line number Diff line number Diff line
@@ -127,6 +127,73 @@ DEFINE_AND_INSTANTIATE_LeReadBufferSizeReflectionTest(le_read_buffer_size);
std::vector<uint8_t> le_read_buffer_size_complete = {0x0e, 0x07, 0x01, 0x02, 0x20, 0x00, 0xfb, 0x00, 0x10};
DEFINE_AND_INSTANTIATE_LeReadBufferSizeCompleteReflectionTest(le_read_buffer_size_complete);

std::vector<uint8_t> write_current_iac_laps = {0x3a, 0x0c, 0x07, 0x02, 0x11, 0x8b, 0x9e, 0x22, 0x8b, 0x9e};
DEFINE_AND_INSTANTIATE_WriteCurrentIacLapReflectionTest(write_current_iac_laps);

std::vector<uint8_t> write_current_iac_laps_complete = {0x0e, 0x04, 0x01, 0x3a, 0x0c, 0x00};
DEFINE_AND_INSTANTIATE_WriteCurrentIacLapCompleteReflectionTest(write_current_iac_laps_complete);

std::vector<uint8_t> write_inquiry_scan_activity = {0x1e, 0x0c, 0x04, 0x00, 0x08, 0x12, 0x00};
DEFINE_AND_INSTANTIATE_WriteInquiryScanActivityReflectionTest(write_inquiry_scan_activity);

std::vector<uint8_t> write_inquiry_scan_activity_complete = {0x0e, 0x04, 0x01, 0x1e, 0x0c, 0x00};
DEFINE_AND_INSTANTIATE_WriteInquiryScanActivityCompleteReflectionTest(write_inquiry_scan_activity_complete);

std::vector<uint8_t> read_inquiry_scan_activity = {0x1d, 0x0c, 0x00};
DEFINE_AND_INSTANTIATE_ReadInquiryScanActivityReflectionTest(read_inquiry_scan_activity);

std::vector<uint8_t> read_inquiry_scan_activity_complete = {0x0e, 0x08, 0x01, 0x1d, 0x0c, 0x00, 0xaa, 0xbb, 0xcc, 0xdd};
DEFINE_AND_INSTANTIATE_ReadInquiryScanActivityCompleteReflectionTest(read_inquiry_scan_activity_complete);

std::vector<uint8_t> read_current_iac_lap = {0x39, 0x0c, 0x00};
DEFINE_AND_INSTANTIATE_ReadCurrentIacLapReflectionTest(read_current_iac_lap);

std::vector<uint8_t> read_current_iac_lap_complete = {0x0e, 0x0b, 0x01, 0x39, 0x0c, 0x00, 0x02,
                                                      0x11, 0x8b, 0x9e, 0x22, 0x8b, 0x9e};
DEFINE_AND_INSTANTIATE_ReadCurrentIacLapCompleteReflectionTest(read_current_iac_lap_complete);

std::vector<uint8_t> read_number_of_supported_iac = {0x38, 0x0c, 0x00};
DEFINE_AND_INSTANTIATE_ReadNumberOfSupportedIacReflectionTest(read_number_of_supported_iac);

std::vector<uint8_t> read_number_of_supported_iac_complete = {0x0e, 0x05, 0x01, 0x38, 0x0c, 0x00, 0x99};
DEFINE_AND_INSTANTIATE_ReadNumberOfSupportedIacCompleteReflectionTest(read_number_of_supported_iac_complete);

std::vector<uint8_t> read_page_timeout = {0x17, 0x0c, 0x00};
DEFINE_AND_INSTANTIATE_ReadPageTimeoutReflectionTest(read_page_timeout);

std::vector<uint8_t> read_page_timeout_complete = {0x0e, 0x06, 0x01, 0x17, 0x0c, 0x00, 0x11, 0x22};
DEFINE_AND_INSTANTIATE_ReadPageTimeoutCompleteReflectionTest(read_page_timeout_complete);

std::vector<uint8_t> write_page_timeout = {0x18, 0x0c, 0x02, 0x00, 0x20};
DEFINE_AND_INSTANTIATE_WritePageTimeoutReflectionTest(write_page_timeout);

std::vector<uint8_t> write_page_timeout_complete = {0x0e, 0x04, 0x01, 0x18, 0x0c, 0x00};
DEFINE_AND_INSTANTIATE_WritePageTimeoutCompleteReflectionTest(write_page_timeout_complete);

std::vector<uint8_t> inquiry = {0x01, 0x04, 0x05, 0x33, 0x8b, 0x9e, 0xaa, 0xbb};
DEFINE_AND_INSTANTIATE_InquiryReflectionTest(inquiry);

std::vector<uint8_t> inquiry_status = {0x0f, 0x04, 0x00, 0x01, 0x01, 0x04};
DEFINE_AND_INSTANTIATE_InquiryStatusReflectionTest(inquiry_status);

std::vector<uint8_t> inquiry_cancel = {0x02, 0x04, 0x00};
DEFINE_AND_INSTANTIATE_InquiryCancelReflectionTest(inquiry_cancel);

std::vector<uint8_t> inquiry_cancel_complete = {0x0e, 0x04, 0x01, 0x02, 0x04, 0x00};
DEFINE_AND_INSTANTIATE_InquiryCancelCompleteReflectionTest(inquiry_cancel_complete);

std::vector<uint8_t> periodic_inquiry_mode = {0x03, 0x04, 0x09, 0x12, 0x34, 0x56, 0x78, 0x11, 0x8b, 0x9e, 0x9a, 0xbc};
DEFINE_AND_INSTANTIATE_PeriodicInquiryModeReflectionTest(periodic_inquiry_mode);

std::vector<uint8_t> periodic_inquiry_mode_complete = {0x0e, 0x04, 0x01, 0x03, 0x04, 0x00};
DEFINE_AND_INSTANTIATE_PeriodicInquiryModeCompleteReflectionTest(periodic_inquiry_mode_complete);

std::vector<uint8_t> exit_periodic_inquiry_mode = {0x04, 0x04, 0x00};
DEFINE_AND_INSTANTIATE_ExitPeriodicInquiryModeReflectionTest(exit_periodic_inquiry_mode);

std::vector<uint8_t> exit_periodic_inquiry_mode_complete = {0x0e, 0x04, 0x01, 0x04, 0x04, 0x00};
DEFINE_AND_INSTANTIATE_ExitPeriodicInquiryModeCompleteReflectionTest(exit_periodic_inquiry_mode_complete);

std::vector<uint8_t> pixel_3_xl_write_extended_inquiry_response{
    0x52, 0x0c, 0xf1, 0x01, 0x0b, 0x09, 0x50, 0x69, 0x78, 0x65, 0x6c, 0x20, 0x33, 0x20, 0x58, 0x4c, 0x19, 0x03, 0x05,
    0x11, 0x0a, 0x11, 0x0c, 0x11, 0x0e, 0x11, 0x12, 0x11, 0x15, 0x11, 0x16, 0x11, 0x1f, 0x11, 0x2d, 0x11, 0x2f, 0x11,
+206 −0
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.
 */
#define LOG_TAG "bt_gd_neigh"

#include "neighbor/scan.h"
#include <memory>
#include "hci/hci_layer.h"
#include "hci/hci_packets.h"
#include "module.h"
#include "os/handler.h"
#include "os/log.h"

namespace bluetooth {
namespace neighbor {

struct ScanModule::impl {
  impl(ScanModule& module);

  void SetInquiryScan(bool enabled);
  bool IsInquiryEnabled() const;

  void SetPageScan(bool enabled);
  bool IsPageEnabled() const;

  void Start();
  void Stop();

 private:
  ScanModule& module_;

  bool inquiry_scan_enabled_;
  bool page_scan_enabled_;

  void WriteScanEnable();
  void ReadScanEnable(hci::ScanEnable);

  void OnCommandComplete(hci::CommandCompleteView status);

  hci::HciLayer* hci_layer_;
  os::Handler* handler_;
};

const ModuleFactory neighbor::ScanModule::Factory = ModuleFactory([]() { return new neighbor::ScanModule(); });

neighbor::ScanModule::impl::impl(neighbor::ScanModule& module)
    : module_(module), inquiry_scan_enabled_(false), page_scan_enabled_(false) {}

void neighbor::ScanModule::impl::OnCommandComplete(hci::CommandCompleteView view) {
  switch veiwstatus.GetCommandOpCode()) {
      case hci::OpCode::READ_SCAN_ENABLE: {
        auto packet = hci::ReadScanEnableCompleteView::Create(view);
        ASSERT(packet.IsValid());
        ASSERT(packet.GetStatus() == hci::ErrorCode::SUCCESS);
        ReadScanEnable(packet.GetScanEnable());
      } break;

      case hci::OpCode::WRITE_SCAN_ENABLE: {
        auto packet = hci::WriteScanEnableCompleteView::Create(view);
        ASSERT(packet.IsValid());
        ASSERT(packet.GetStatus() == hci::ErrorCode::SUCCESS);
      } break;

      default:
        LOG_ERROR("Unhandled command %s", hci::OpCodeText(view.GetCommandOpCode()).c_str());
        break;
    }
}

void neighbor::ScanModule::impl::WriteScanEnable() {
  hci::ScanEnable scan_enable;

  if (inquiry_scan_enabled_ && !page_scan_enabled_) {
    scan_enable = hci::ScanEnable::INQUIRY_SCAN_ONLY;
  } else if (!inquiry_scan_enabled_ && page_scan_enabled_) {
    scan_enable = hci::ScanEnable::PAGE_SCAN_ONLY;
  } else if (inquiry_scan_enabled_ && page_scan_enabled_) {
    scan_enable = hci::ScanEnable::INQUIRY_AND_PAGE_SCAN;
  } else {
    scan_enable = hci::ScanEnable::NO_SCANS;
  }

  {
    std::unique_ptr<hci::WriteScanEnableBuilder> packet = hci::WriteScanEnableBuilder::Create(scan_enable);
    hci_layer_->EnqueueCommand(std::move(packet), common::BindOnce(&impl::OnCommandComplete, common::Unretained(this)),
                               handler_);
  }

  {
    std::unique_ptr<hci::ReadScanEnableBuilder> packet = hci::ReadScanEnableBuilder::Create();
    hci_layer_->EnqueueCommand(std::move(packet), common::BindOnce(&impl::OnCommandComplete, common::Unretained(this)),
                               handler_);
  }
}

void neighbor::ScanModule::impl::ReadScanEnable(hci::ScanEnable scan_enable) {
  switch (scan_enable) {
    case hci::ScanEnable::INQUIRY_SCAN_ONLY:
      inquiry_scan_enabled_ = true;
      page_scan_enabled_ = false;
      break;

    case hci::ScanEnable::PAGE_SCAN_ONLY:
      inquiry_scan_enabled_ = false;
      page_scan_enabled_ = true;
      break;

    case hci::ScanEnable::INQUIRY_AND_PAGE_SCAN:
      inquiry_scan_enabled_ = true;
      page_scan_enabled_ = true;
      break;

    default:
      inquiry_scan_enabled_ = false;
      page_scan_enabled_ = false;
      break;
  }
}

void neighbor::ScanModule::impl::SetInquiryScan(bool enabled) {
  inquiry_scan_enabled_ = enabled;
  WriteScanEnable();
}

void neighbor::ScanModule::impl::SetPageScan(bool enabled) {
  page_scan_enabled_ = enabled;
  WriteScanEnable();
}

bool neighbor::ScanModule::impl::IsInquiryEnabled() const {
  return inquiry_scan_enabled_;
}

bool neighbor::ScanModule::impl::IsPageEnabled() const {
  return page_scan_enabled_;
}

void neighbor::ScanModule::impl::Start() {
  hci_layer_ = module_.GetDependency<hci::HciLayer>();
  handler_ = module_.GetHandler();

  std::unique_ptr<hci::ReadScanEnableBuilder> packet = hci::ReadScanEnableBuilder::Create();
  hci_layer_->EnqueueCommand(std::move(packet), common::BindOnce(&impl::OnCommandComplete, common::Unretained(this)),
                             handler_);
}

void neighbor::ScanModule::impl::Stop() {
  LOG_DEBUG("inquiry scan enabled:%d page scan enabled:%d", inquiry_scan_enabled_, page_scan_enabled_);
}

neighbor::ScanModule::ScanModule() : pimpl_(std::make_unique<impl>(*this)) {}

neighbor::ScanModule::~ScanModule() {
  pimpl_.reset();
}

void neighbor::ScanModule::SetInquiryScan() {
  pimpl_->SetInquiryScan(true);
}

void neighbor::ScanModule::ClearInquiryScan() {
  pimpl_->SetInquiryScan(false);
}

void neighbor::ScanModule::SetPageScan() {
  pimpl_->SetPageScan(true);
}

void neighbor::ScanModule::ClearPageScan() {
  pimpl_->SetPageScan(false);
}

bool neighbor::ScanModule::IsInquiryEnabled() const {
  return pimpl_->IsInquiryEnabled();
}

bool neighbor::ScanModule::IsPageEnabled() const {
  return pimpl_->IsPageEnabled();
}

void neighbor::ScanModule::ListDependencies(ModuleList* list) {
  list->add<hci::HciLayer>();
}

void neighbor::ScanModule::Start() {
  pimpl_->Start();
}

void neighbor::ScanModule::Stop() {
  pimpl_->Stop();
}

}  // namespace neighbor
}  // namespace bluetooth
+53 −0
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 "module.h"

namespace bluetooth {
namespace neighbor {

class ScanModule : public bluetooth::Module {
 public:
  ScanModule();
  ~ScanModule();

  void SetInquiryScan();
  void ClearInquiryScan();
  bool IsInquiryEnabled() const;

  void SetPageScan();
  void ClearPageScan();
  bool IsPageEnabled() const;

  static const ModuleFactory Factory;

 protected:
  void ListDependencies(ModuleList* list) override;
  void Start() override;
  void Stop() override;

 private:
  struct impl;
  std::unique_ptr<impl> pimpl_;

  DISALLOW_COPY_AND_ASSIGN(ScanModule);
};

}  // namespace neighbor
}  // namespace bluetooth
Loading