From 751381c64fee63590f0888c8eac5c8a474f1e25b Mon Sep 17 00:00:00 2001 From: Jakub Pawlowski Date: Wed, 30 Nov 2016 13:51:01 -0800 Subject: [PATCH] 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 --- device/src/controller.cc | 2 +- stack/btm/ble_advertiser_hci_interface.cc | 34 ++++++++++++++++++++++++++++++- stack/btm/btm_ble_int.h | 1 + stack/btm/btm_ble_multi_adv.cc | 6 +++--- stack/btu/btu_hcif.cc | 4 ++++ stack/include/hcidefs.h | 1 + 6 files changed, 43 insertions(+), 5 deletions(-) diff --git a/device/src/controller.cc b/device/src/controller.cc index 45b71016d..ac50ee7c5 100644 --- a/device/src/controller.cc +++ b/device/src/controller.cc @@ -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}; diff --git a/stack/btm/ble_advertiser_hci_interface.cc b/stack/btm/ble_advertiser_hci_interface.cc index 44af09c2d..0c48fdb30 100644 --- a/stack/btm/ble_advertiser_hci_interface.cc +++ b/stack/btm/ble_advertiser_hci_interface.cc @@ -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."; diff --git a/stack/btm/btm_ble_int.h b/stack/btm/btm_ble_int.h index 63e094e10..f3caadddb 100644 --- a/stack/btm/btm_ble_int.h +++ b/stack/btm/btm_ble_int.h @@ -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); diff --git a/stack/btm/btm_ble_multi_adv.cc b/stack/btm/btm_ble_multi_adv.cc index 407f1c74e..98c0a0917 100644 --- a/stack/btm/btm_ble_multi_adv.cc +++ b/stack/btm/btm_ble_multi_adv.cc @@ -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) { diff --git a/stack/btu/btu_hcif.cc b/stack/btu/btu_hcif.cc index 5a0187a30..f97b9d4c1 100644 --- a/stack/btu/btu_hcif.cc +++ b/stack/btu/btu_hcif.cc @@ -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: diff --git a/stack/include/hcidefs.h b/stack/include/hcidefs.h index 9f4f98c1c..e98c12cb2 100644 --- a/stack/include/hcidefs.h +++ b/stack/include/hcidefs.h @@ -827,6 +827,7 @@ #define HCI_BLE_DATA_LENGTH_CHANGE_EVT 0x07 #define HCI_BLE_ENHANCED_CONN_COMPLETE_EVT 0x0a #define HCI_BLE_DIRECT_ADV_EVT 0x0b +#define HCI_LE_ADVERTISING_SET_TERMINATED_EVT 0x12 /* Definitions for LE Channel Map */ #define HCI_BLE_CHNL_MAP_SIZE 5 -- 2.11.0