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

Commit a618d3a4 authored by Jakub Pawlowski's avatar Jakub Pawlowski
Browse files

Handle Advertising Set Terminated event

Make BleAdvertiserHciExtendedImpl report when advertising set is
disabled because of new connection.

Bug: 30622771
Test: sl4a ConcurrentBleAdvertisingTest
Change-Id: Ic13a31fe4bb92f121a29d540274d13893775a450
parent 0b6cd537
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -31,7 +31,7 @@
#include "stack/include/btm_ble_api.h"

const bt_event_mask_t BLE_EVENT_MASK = {
    {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x7f}};
    {0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x06, 0x7f}};

const bt_event_mask_t CLASSIC_EVENT_MASK = {HCI_DUMO_EVENT_MASK_EXT};

+33 −1
Original line number Diff line number Diff line
@@ -347,7 +347,9 @@ class BleAdvertiserHciExtendedImpl : public BleAdvertiserHciInterface {
  }

  void SetAdvertisingEventObserver(
      AdvertisingEventObserver* observer) override {}
      AdvertisingEventObserver* observer) override {
    this->advertising_event_observer = observer;
  }

  void SetParameters(uint8_t adv_int_min, uint8_t adv_int_max,
                     uint8_t advertising_type, uint8_t own_address_type,
@@ -469,10 +471,40 @@ class BleAdvertiserHciExtendedImpl : public BleAdvertiserHciInterface {
    SendAdvCmd(HCI_LE_SET_EXT_ADVERTISING_ENABLE, param, cmd_length,
               command_complete);
  }

 public:
  void OnAdvertisingSetTerminated(uint8_t length, uint8_t* p) {
    VLOG(1) << __func__;
    LOG_ASSERT(p);
    uint8_t status, advertising_handle, num_completed_adv_evt;
    uint16_t conn_handle;

    STREAM_TO_UINT8(status, p);
    STREAM_TO_UINT8(advertising_handle, p);
    STREAM_TO_UINT16(conn_handle, p);
    STREAM_TO_UINT8(num_completed_adv_evt, p);

    conn_handle = conn_handle & 0x0FFF;  // only 12 bits meaningful

    AdvertisingEventObserver* observer = this->advertising_event_observer;
    if (observer)
      observer->OnAdvertisingStateChanged(advertising_handle, 0x00,
                                          conn_handle);
  }

 private:
  AdvertisingEventObserver* advertising_event_observer = nullptr;
};

}  // namespace

void btm_le_on_advertising_set_terminated(uint8_t* p, uint16_t length) {
  if (BleAdvertiserHciInterface::Get()) {
    ((BleAdvertiserHciExtendedImpl*)BleAdvertiserHciInterface::Get())
        ->OnAdvertisingSetTerminated(length, p);
  }
}

void BleAdvertiserHciInterface::Initialize() {
  VLOG(1) << __func__;
  LOG_ASSERT(instance == nullptr) << "Was already initialized.";
+1 −0
Original line number Diff line number Diff line
@@ -69,6 +69,7 @@ extern tBTM_BLE_CONN_ST btm_ble_get_conn_st(void);
extern void btm_ble_set_conn_st(tBTM_BLE_CONN_ST new_st);
extern tBTM_STATUS btm_ble_start_adv(void);
extern tBTM_STATUS btm_ble_stop_adv(void);
extern void btm_le_on_advertising_set_terminated(uint8_t* p, uint16_t length);
extern tBTM_STATUS btm_ble_start_scan(void);
extern void btm_ble_create_ll_conn_complete(uint8_t status);

+3 −3
Original line number Diff line number Diff line
@@ -398,9 +398,9 @@ class BleAdvertisingManagerImpl
  void OnAdvertisingStateChanged(uint8_t inst_id, uint8_t reason,
                                 uint16_t conn_handle) override {
    AdvertisingInstance* p_inst = &adv_inst[inst_id];
    VLOG(1) << __func__ << " inst_id: 0x" << std::hex << inst_id
            << ", reason: 0x" << std::hex << reason << ", conn_handle: 0x"
            << std::hex << conn_handle;
    VLOG(1) << __func__ << " inst_id: 0x" << std::hex << +inst_id
            << ", reason: 0x" << std::hex << +reason << ", conn_handle: 0x"
            << std::hex << +conn_handle;

#if (BLE_PRIVACY_SPT == TRUE)
    if (BTM_BleLocalPrivacyEnabled() && inst_id <= BTM_BLE_MULTI_ADV_MAX) {
+4 −0
Original line number Diff line number Diff line
@@ -326,6 +326,10 @@ void btu_hcif_process_event(UNUSED_ATTR uint8_t controller_id, BT_HDR* p_msg) {
        case HCI_BLE_DATA_LENGTH_CHANGE_EVT:
          btu_ble_data_length_change_evt(p, hci_evt_len);
          break;

        case HCI_LE_ADVERTISING_SET_TERMINATED_EVT:
          btm_le_on_advertising_set_terminated(p, hci_evt_len);
          break;
      }
      break;
    case HCI_VENDOR_SPECIFIC_EVT:
Loading