]> granicus.if.org Git - esp-idf/commitdiff
component/bt: add a option to make report adv data and scan response individually
authorTian Hao <tianhao@espressif.com>
Wed, 23 Jan 2019 06:11:56 +0000 (14:11 +0800)
committerTian Hao <tianhao@espressif.com>
Thu, 24 Jan 2019 06:43:36 +0000 (14:43 +0800)
Originally, when doing BLE active scan, Bluedroid will not report adv to
application layer until receive scan response. This option is used to
disable the behavior. When enable this option, Bluedroid will report
adv data or scan response to application layer immediately.

components/bt/Kconfig
components/bt/bluedroid/common/include/common/bt_target.h
components/bt/bluedroid/stack/btm/btm_ble_gap.c
examples/bluetooth/gatt_client/main/Kconfig.projbuild [new file with mode: 0644]
examples/bluetooth/gatt_client/main/gattc_demo.c

index f018d6d0360c594cf14ea8048dd60ad904fe717e..b84c07b27fa528b5193a677b93c1cdbbb255a148 100644 (file)
@@ -1185,6 +1185,15 @@ config SMP_ENABLE
    depends on BLUEDROID_ENABLED
    default CLASSIC_BT_ENABLED || BLE_SMP_ENABLE
 
+config BLE_ACTIVE_SCAN_REPORT_ADV_SCAN_RSP_INDIVIDUALLY
+    bool "Report adv data and scan response individually when BLE active scan"
+    depends on BLUEDROID_ENABLED && (BTDM_CONTROLLER_MODE_BTDM || BTDM_CONTROLLER_MODE_BLE_ONLY)
+    default n
+    help
+        Originally, when doing BLE active scan, Bluedroid will not report adv to application layer
+        until receive scan response. This option is used to disable the behavior. When enable this option,
+        Bluedroid will report adv data or scan response to application layer immediately.
+
 # Memory reserved at start of DRAM for Bluetooth stack
 config BT_RESERVE_DRAM
     hex
index 5c415a2b6d7f34331e4c6d1467c714e4878bb043..3cf75b918eccfb2c5b398c7f8a0c79566f6ed070 100644 (file)
 #define GATTS_SEND_SERVICE_CHANGE_MODE CONFIG_GATTS_SEND_SERVICE_CHANGE_MODE
 #endif
 
+#ifndef CONFIG_BLE_ACTIVE_SCAN_REPORT_ADV_SCAN_RSP_INDIVIDUALLY
+#define BTM_BLE_ACTIVE_SCAN_REPORT_ADV_SCAN_RSP_INDIVIDUALLY    FALSE
+#else
+#define BTM_BLE_ACTIVE_SCAN_REPORT_ADV_SCAN_RSP_INDIVIDUALLY    CONFIG_BLE_ACTIVE_SCAN_REPORT_ADV_SCAN_RSP_INDIVIDUALLY
+#endif
+
 /* This feature is used to eanble interleaved scan*/
 #ifndef BTA_HOST_INTERLEAVE_SEARCH
 #define BTA_HOST_INTERLEAVE_SEARCH FALSE//FALSE
index 2bbd8e3ea7286acec3d76281b0072991803eacce..445cf03570decbf3b91876227232ea93e1d2c2ae 100644 (file)
@@ -3019,7 +3019,9 @@ BOOLEAN btm_ble_update_inq_result(BD_ADDR bda, tINQ_DB_ENT *p_i, UINT8 addr_type
         BTM_TRACE_DEBUG("btm_ble_update_inq_result scan_rsp=false, to_report=false,\
                               scan_type_active=%d", btm_cb.ble_ctr_cb.inq_var.scan_type);
         p_i->scan_rsp = FALSE;
+#if BTM_BLE_ACTIVE_SCAN_REPORT_ADV_SCAN_RSP_INDIVIDUALLY == FALSE
         to_report = FALSE;
+#endif
     } else {
         p_i->scan_rsp = TRUE;
     }
diff --git a/examples/bluetooth/gatt_client/main/Kconfig.projbuild b/examples/bluetooth/gatt_client/main/Kconfig.projbuild
new file mode 100644 (file)
index 0000000..15378b1
--- /dev/null
@@ -0,0 +1,7 @@
+menu "Example Configuration"
+
+    config EXAMPLE_DUMP_ADV_DATA_AND_SCAN_RESP
+        bool "Dump whole adv data and scan response data in example"
+        default n
+
+endmenu
index 43799fe85314b41d6315e2bc3723933a66bf3d06..9f8fb45617f0924395eb0ea246ac6a7e0239ea25 100644 (file)
@@ -338,7 +338,19 @@ static void esp_gap_cb(esp_gap_ble_cb_event_t event, esp_ble_gap_cb_param_t *par
                                                 ESP_BLE_AD_TYPE_NAME_CMPL, &adv_name_len);
             ESP_LOGI(GATTC_TAG, "searched Device Name Len %d", adv_name_len);
             esp_log_buffer_char(GATTC_TAG, adv_name, adv_name_len);
+
+#if CONFIG_EXAMPLE_DUMP_ADV_DATA_AND_SCAN_RESP
+            if (scan_result->scan_rst.adv_data_len > 0) {
+                ESP_LOGI(GATTC_TAG, "adv data:");
+                esp_log_buffer_hex(GATTC_TAG, &scan_result->scan_rst.ble_adv[0], scan_result->scan_rst.adv_data_len);
+            }
+            if (scan_result->scan_rst.scan_rsp_len > 0) {
+                ESP_LOGI(GATTC_TAG, "scan resp:");
+                esp_log_buffer_hex(GATTC_TAG, &scan_result->scan_rst.ble_adv[scan_result->scan_rst.adv_data_len], scan_result->scan_rst.scan_rsp_len);
+            }
+#endif
             ESP_LOGI(GATTC_TAG, "\n");
+
             if (adv_name != NULL) {
                 if (strlen(remote_device_name) == adv_name_len && strncmp((char *)adv_name, remote_device_name, adv_name_len) == 0) {
                     ESP_LOGI(GATTC_TAG, "searched device %s\n", remote_device_name);