OSDN Git Service

Handle Advertising Set Terminated event
authorJakub Pawlowski <jpawlowski@google.com>
Wed, 30 Nov 2016 21:51:01 +0000 (13:51 -0800)
committerJakub Pawlowski <jpawlowski@google.com>
Mon, 19 Dec 2016 22:24:37 +0000 (14:24 -0800)
Make BleAdvertiserHciExtendedImpl report when advertising set is
disabled because of new connection.

Bug: 30622771
Test: sl4a ConcurrentBleAdvertisingTest
Change-Id: Ic13a31fe4bb92f121a29d540274d13893775a450

device/src/controller.cc
stack/btm/ble_advertiser_hci_interface.cc
stack/btm/btm_ble_int.h
stack/btm/btm_ble_multi_adv.cc
stack/btu/btu_hcif.cc
stack/include/hcidefs.h

index 45b7101..ac50ee7 100644 (file)
@@ -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};
 
index 44af09c..0c48fdb 100644 (file)
@@ -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.";
index 63e094e..f3caadd 100644 (file)
@@ -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);
 
index 407f1c7..98c0a09 100644 (file)
@@ -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) {
index 5a0187a..f97b9d4 100644 (file)
@@ -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:
index 9f4f98c..e98c12c 100644 (file)
 #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