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

Commit 4921ea45 authored by Myles Watson's avatar Myles Watson
Browse files

HCI: Add LE advertising and scanning interfaces

Bug: 139080884
Test: builds
Change-Id: Iea96dc023e2e59f9969b65208881a9f407d4b461
parent dfc12a65
Loading
Loading
Loading
Loading
+54 −0
Original line number Diff line number Diff line
@@ -133,6 +133,42 @@ class LeSecurityInterfaceImpl : public LeSecurityInterface {
  HciLayer& hci_;
};

class LeAdvertisingInterfaceImpl : public LeAdvertisingInterface {
 public:
  LeAdvertisingInterfaceImpl(HciLayer& hci) : hci_(hci) {}
  virtual ~LeAdvertisingInterfaceImpl() = default;

  virtual void EnqueueCommand(std::unique_ptr<LeAdvertisingCommandBuilder> command,
                              common::OnceCallback<void(CommandCompleteView)> on_complete,
                              os::Handler* handler) override {
    hci_.EnqueueCommand(std::move(command), std::move(on_complete), handler);
  }

  virtual void EnqueueCommand(std::unique_ptr<LeAdvertisingCommandBuilder> command,
                              common::OnceCallback<void(CommandStatusView)> on_status, os::Handler* handler) override {
    hci_.EnqueueCommand(std::move(command), std::move(on_status), handler);
  }
  HciLayer& hci_;
};

class LeScanningInterfaceImpl : public LeScanningInterface {
 public:
  LeScanningInterfaceImpl(HciLayer& hci) : hci_(hci) {}
  virtual ~LeScanningInterfaceImpl() = default;

  virtual void EnqueueCommand(std::unique_ptr<LeScanningCommandBuilder> command,
                              common::OnceCallback<void(CommandCompleteView)> on_complete,
                              os::Handler* handler) override {
    hci_.EnqueueCommand(std::move(command), std::move(on_complete), handler);
  }

  virtual void EnqueueCommand(std::unique_ptr<LeScanningCommandBuilder> command,
                              common::OnceCallback<void(CommandStatusView)> on_status, os::Handler* handler) override {
    hci_.EnqueueCommand(std::move(command), std::move(on_status), handler);
  }
  HciLayer& hci_;
};

struct HciLayer::impl : public hal::HciHalCallbacks {
  impl(HciLayer& module) : hal_(nullptr), module_(module) {}

@@ -385,6 +421,8 @@ struct HciLayer::impl : public hal::HciHalCallbacks {
  // Interfaces
  SecurityInterfaceImpl security_interface{module_};
  LeSecurityInterfaceImpl le_security_interface{module_};
  LeAdvertisingInterfaceImpl le_advertising_interface{module_};
  LeScanningInterfaceImpl le_scanning_interface{module_};

  // Command Handling
  std::list<CommandQueueEntry> command_queue_;
@@ -454,6 +492,22 @@ LeSecurityInterface* HciLayer::GetLeSecurityInterface(common::Callback<void(LeMe
  return &impl_->le_security_interface;
}

LeAdvertisingInterface* HciLayer::GetLeAdvertisingInterface(common::Callback<void(LeMetaEventView)> event_handler,
                                                            os::Handler* handler) {
  for (const auto subevent : LeAdvertisingInterface::LeAdvertisingEvents) {
    RegisterLeEventHandler(subevent, event_handler, handler);
  }
  return &impl_->le_advertising_interface;
}

LeScanningInterface* HciLayer::GetLeScanningInterface(common::Callback<void(LeMetaEventView)> event_handler,
                                                      os::Handler* handler) {
  for (const auto subevent : LeScanningInterface::LeScanningEvents) {
    RegisterLeEventHandler(subevent, event_handler, handler);
  }
  return &impl_->le_scanning_interface;
}

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

void HciLayer::ListDependencies(ModuleList* list) {
+8 −0
Original line number Diff line number Diff line
@@ -25,6 +25,8 @@
#include "common/callback.h"
#include "hal/hci_hal.h"
#include "hci/hci_packets.h"
#include "hci/le_advertising_interface.h"
#include "hci/le_scanning_interface.h"
#include "hci/le_security_interface.h"
#include "hci/security_interface.h"
#include "module.h"
@@ -62,6 +64,12 @@ class HciLayer : public Module {
  LeSecurityInterface* GetLeSecurityInterface(common::Callback<void(LeMetaEventView)> event_handler,
                                              os::Handler* handler);

  LeAdvertisingInterface* GetLeAdvertisingInterface(common::Callback<void(LeMetaEventView)> event_handler,
                                                    os::Handler* handler);

  LeScanningInterface* GetLeScanningInterface(common::Callback<void(LeMetaEventView)> event_handler,
                                              os::Handler* handler);

  static const ModuleFactory Factory;

  void ListDependencies(ModuleList* list) override;
+3 −2
Original line number Diff line number Diff line
@@ -549,6 +549,7 @@ packet ConnectionManagementCommand : CommandPacket { _payload_, }
packet SecurityCommand : CommandPacket { _payload_, }
packet ScoConnectionCommand : CommandPacket { _payload_, }
packet LeAdvertisingCommand : CommandPacket { _payload_, }
packet LeScanningCommand : CommandPacket { _payload_, }
packet LeConnectionManagementCommand : CommandPacket { _payload_, }
packet LeSecurityCommand : CommandPacket { _payload_, }
packet VendorCommand : CommandPacket { _payload_, }
@@ -2286,7 +2287,7 @@ enum LeSetScanningFilterPolicy : 8 {
  WHITE_LIST_AND_INITIATORS_IDENTITY = 0x03,
}

packet LeSetScanParameters : LeAdvertisingCommand (op_code = LE_SET_SCAN_PARAMETERS) {
packet LeSetScanParameters : LeScanningCommand (op_code = LE_SET_SCAN_PARAMETERS) {
  le_scan_type : LeScanType,
  le_scan_interval : 16, // 0x0004-0x4000 Default 0x10 (10ms)
  le_scan_window : 16, // Default 0x10 (10ms)
@@ -2298,7 +2299,7 @@ packet LeSetScanParametersComplete : CommandComplete (command_op_code = LE_SET_S
  status : ErrorCode,
}

packet LeSetScanEnable : LeAdvertisingCommand (op_code = LE_SET_SCAN_ENABLE) {
packet LeSetScanEnable : LeScanningCommand (op_code = LE_SET_SCAN_ENABLE) {
  le_scan_enable : Enable,
  filter_duplicates : Enable,
}
+50 −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 "common/callback.h"
#include "hci/hci_packets.h"
#include "os/handler.h"
#include "os/utils.h"

namespace bluetooth {
namespace hci {

class LeAdvertisingInterface {
 public:
  LeAdvertisingInterface() = default;
  virtual ~LeAdvertisingInterface() = default;
  DISALLOW_COPY_AND_ASSIGN(LeAdvertisingInterface);

  virtual void EnqueueCommand(std::unique_ptr<LeAdvertisingCommandBuilder> command,
                              common::OnceCallback<void(CommandCompleteView)> on_complete, os::Handler* handler) = 0;

  virtual void EnqueueCommand(std::unique_ptr<LeAdvertisingCommandBuilder> command,
                              common::OnceCallback<void(CommandStatusView)> on_status, os::Handler* handler) = 0;

  static constexpr hci::SubeventCode LeAdvertisingEvents[] = {
      hci::SubeventCode::ADVERTISING_REPORT,
      hci::SubeventCode::DIRECTED_ADVERTISING_REPORT,
      hci::SubeventCode::EXTENDED_ADVERTISING_REPORT,
      hci::SubeventCode::PERIODIC_ADVERTISING_REPORT,
      hci::SubeventCode::PERIODIC_ADVERTISING_SYNC_ESTABLISHED,
      hci::SubeventCode::PERIODIC_ADVERTISING_SYNC_LOST,
      hci::SubeventCode::SCAN_REQUEST_RECEIVED,
  };
};
}  // namespace hci
}  // namespace bluetooth
+44 −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 "common/callback.h"
#include "hci/hci_packets.h"
#include "os/handler.h"
#include "os/utils.h"

namespace bluetooth {
namespace hci {

class LeScanningInterface {
 public:
  LeScanningInterface() = default;
  virtual ~LeScanningInterface() = default;
  DISALLOW_COPY_AND_ASSIGN(LeScanningInterface);

  virtual void EnqueueCommand(std::unique_ptr<LeScanningCommandBuilder> command,
                              common::OnceCallback<void(CommandCompleteView)> on_complete, os::Handler* handler) = 0;

  virtual void EnqueueCommand(std::unique_ptr<LeScanningCommandBuilder> command,
                              common::OnceCallback<void(CommandStatusView)> on_status, os::Handler* handler) = 0;

  static constexpr hci::SubeventCode LeScanningEvents[] = {
      hci::SubeventCode::SCAN_TIMEOUT,
  };
};
}  // namespace hci
}  // namespace bluetooth