You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by cc...@apache.org on 2016/07/13 20:55:15 UTC

[02/50] [abbrv] incubator-mynewt-core git commit: BLE Host - handle direct advertising report event.

BLE Host - handle direct advertising report event.


Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/commit/e4c0c0ad
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/e4c0c0ad
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/e4c0c0ad

Branch: refs/heads/develop
Commit: e4c0c0ad4966a7329de4d3ea317a4f2061896732
Parents: 9e781e9
Author: Christopher Collins <cc...@apache.org>
Authored: Thu Jun 23 20:34:36 2016 -0700
Committer: Christopher Collins <cc...@apache.org>
Committed: Mon Jul 11 16:43:31 2016 -0700

----------------------------------------------------------------------
 net/nimble/host/include/host/ble_gap.h      | 16 +++-
 net/nimble/host/src/ble_eddystone.c         |  1 +
 net/nimble/host/src/ble_gap.c               | 44 +++++------
 net/nimble/host/src/ble_gap_priv.h          |  2 +-
 net/nimble/host/src/ble_hs_adv.c            |  1 +
 net/nimble/host/src/ble_hs_adv_priv.h       | 35 ---------
 net/nimble/host/src/ble_hs_priv.h           |  2 +-
 net/nimble/host/src/ble_ibeacon.c           |  1 +
 net/nimble/host/src/host_hci.c              | 97 ++++++++++++++++++++----
 net/nimble/host/src/test/ble_gap_test.c     | 32 ++++----
 net/nimble/host/src/test/ble_hs_adv_test.c  |  1 +
 net/nimble/host/src/test/ble_hs_conn_test.c |  1 +
 net/nimble/host/src/test/ble_hs_test_util.c |  1 +
 net/nimble/include/nimble/hci_common.h      |  3 +
 14 files changed, 146 insertions(+), 91 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/e4c0c0ad/net/nimble/host/include/host/ble_gap.h
----------------------------------------------------------------------
diff --git a/net/nimble/host/include/host/ble_gap.h b/net/nimble/host/include/host/ble_gap.h
index 707b10b..90b3f85 100644
--- a/net/nimble/host/include/host/ble_gap.h
+++ b/net/nimble/host/include/host/ble_gap.h
@@ -43,9 +43,12 @@ struct hci_conn_update;
 /** 60 ms; active scanning. */
 #define BLE_GAP_SCAN_FAST_INTERVAL_MAX      (60 * 1000 / BLE_HCI_ADV_ITVL)
 
-/** 11.25 seconds; limited discovery interval. */
+/** 11.25 ms; limited discovery interval. */
 #define BLE_GAP_LIM_DISC_SCAN_INT           (11.25 * 1000 / BLE_HCI_SCAN_ITVL)
 
+/** 11.25 ms; limited discovery window (not from the spec). */
+#define BLE_GAP_LIM_DISC_SCAN_WINDOW        (11.25 * 1000 / BLE_HCI_SCAN_ITVL)
+
 /** 30 ms; active scanning. */
 #define BLE_GAP_SCAN_FAST_WINDOW            (30 * 1000 / BLE_HCI_SCAN_ITVL)
 
@@ -90,6 +93,7 @@ struct hci_conn_update;
 #define BLE_GAP_APPEARANCE_GEN_COMPUTER                 128
 
 #define BLE_GAP_ADDR_TYPE_WL                0xff
+#define BLE_GAP_ADDR_TYPE_NONE              0xfe
 
 #define BLE_GAP_EVENT_CONNECT               0
 #define BLE_GAP_EVENT_DISCONNECT            1
@@ -245,13 +249,23 @@ typedef int ble_gap_event_fn(int event, struct ble_gap_conn_ctxt *ctxt,
                              void *arg);
 
 struct ble_gap_disc_desc {
+    /*** Common fields. */
     uint8_t event_type;
     uint8_t addr_type;
     uint8_t length_data;
     int8_t rssi;
     uint8_t addr[6];
+
+    /*** LE advertising report fields; both null if no data present. */
     uint8_t *data;
     struct ble_hs_adv_fields *fields;
+
+    /***
+     * LE direct advertising report fields; direct_addr_type is
+     * BLE_GAP_ADDR_TYPE_NONE if direct address fields are not present.
+     */
+    uint8_t direct_addr_type;
+    uint8_t direct_addr[6];
 };
 
 typedef void ble_gap_disc_fn(int event, int status,

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/e4c0c0ad/net/nimble/host/src/ble_eddystone.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_eddystone.c b/net/nimble/host/src/ble_eddystone.c
index dbd8a71..2030c79 100644
--- a/net/nimble/host/src/ble_eddystone.c
+++ b/net/nimble/host/src/ble_eddystone.c
@@ -19,6 +19,7 @@
 
 #include <string.h>
 #include "host/ble_eddystone.h"
+#include "host/ble_hs_adv.h"
 #include "ble_hs_priv.h"
 
 #define BLE_EDDYSTONE_MAX_SVC_DATA_LEN  23

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/e4c0c0ad/net/nimble/host/src/ble_gap.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_gap.c b/net/nimble/host/src/ble_gap.c
index 57502f8..cf80b7e 100644
--- a/net/nimble/host/src/ble_gap.c
+++ b/net/nimble/host/src/ble_gap.c
@@ -24,6 +24,7 @@
 #include "os/os.h"
 #include "nimble/nimble_opt.h"
 #include "host/host_hci.h"
+#include "host/ble_hs_adv.h"
 #include "ble_hs_priv.h"
 
 /**
@@ -497,27 +498,15 @@ ble_gap_master_connect_cancel(void)
 }
 
 static void
-ble_gap_call_master_disc_cb(int event, int status, struct ble_hs_adv *adv,
+ble_gap_call_master_disc_cb(int event, int status,
+                            struct ble_gap_disc_desc *desc,
                             struct ble_hs_adv_fields *fields, int reset_state)
 {
-    struct ble_gap_disc_desc desc;
     ble_gap_disc_fn *cb;
     void *cb_arg;
 
     ble_hs_lock();
 
-    if (adv != NULL) {
-        desc.event_type = adv->event_type;
-        desc.addr_type = adv->addr_type;
-        desc.length_data = adv->length_data;
-        desc.rssi = adv->rssi;
-        memcpy(desc.addr, adv->addr, sizeof adv->addr);
-        desc.data = adv->data;
-        desc.fields = fields;
-    } else {
-        memset(&desc, 0, sizeof desc);
-    }
-
     cb = ble_gap_master.disc.cb;
     cb_arg = ble_gap_master.disc.cb_arg;
 
@@ -528,7 +517,7 @@ ble_gap_call_master_disc_cb(int event, int status, struct ble_hs_adv *adv,
     ble_hs_unlock();
 
     if (cb != NULL) {
-        cb(event, status, &desc, cb_arg);
+        cb(event, status, desc, cb_arg);
     }
 }
 
@@ -870,7 +859,7 @@ ble_gap_accept_slave_conn(uint8_t addr_type, uint8_t *addr)
 }
 
 void
-ble_gap_rx_adv_report(struct ble_hs_adv *adv)
+ble_gap_rx_adv_report(struct ble_gap_disc_desc *desc)
 {
 #if !NIMBLE_OPT(ROLE_OBSERVER)
     return;
@@ -885,19 +874,22 @@ ble_gap_rx_adv_report(struct ble_hs_adv *adv)
         return;
     }
 
-    rc = ble_hs_adv_parse_fields(&fields, adv->data, adv->length_data);
+    rc = ble_hs_adv_parse_fields(&fields, desc->data, desc->length_data);
     if (rc != 0) {
         /* XXX: Increment stat. */
         return;
     }
 
+    /* If a limited discovery procedure is active, discard non-limited
+     * advertisements.
+     */
     if (ble_gap_master.disc.limited &&
         !(fields.flags & BLE_HS_ADV_F_DISC_LTD)) {
 
         return;
     }
 
-    ble_gap_call_master_disc_cb(BLE_GAP_EVENT_DISC_SUCCESS, 0, adv,
+    ble_gap_call_master_disc_cb(BLE_GAP_EVENT_DISC_SUCCESS, 0, desc,
                                 &fields, 0);
 }
 
@@ -1777,7 +1769,9 @@ ble_gap_disc_tx_params(uint8_t own_addr_type,
                                                own_addr_type,
                                                disc_params->filter_policy,
                                                buf, sizeof buf);
-    BLE_HS_DBG_ASSERT_EVAL(rc == 0);
+    if (rc != 0) {
+        return BLE_HS_EINVAL;
+    }
 
     rc = ble_hci_cmd_tx_empty_ack(buf);
     if (rc != 0) {
@@ -1834,12 +1828,16 @@ ble_gap_disc_fill_dflts(struct ble_gap_disc_params *disc_params)
         if (disc_params->limited) {
             disc_params->itvl = BLE_GAP_LIM_DISC_SCAN_INT;
         } else {
-            disc_params->itvl = BLE_GAP_SCAN_SLOW_INTERVAL1;
+            disc_params->itvl = BLE_GAP_SCAN_FAST_INTERVAL_MIN;
         }
     }
 
     if (disc_params->window == 0) {
-        disc_params->window = BLE_GAP_SCAN_SLOW_WINDOW1;
+        if (disc_params->limited) {
+            disc_params->window = BLE_GAP_LIM_DISC_SCAN_WINDOW;
+        } else {
+            disc_params->window = BLE_GAP_SCAN_FAST_WINDOW;
+        }
     }
 }
 
@@ -1855,10 +1853,6 @@ ble_gap_disc_validate(uint8_t own_addr_type,
         return BLE_HS_EINVAL;
     }
 
-    if (disc_params->filter_policy > BLE_HCI_SCAN_FILT_MAX) {
-        return BLE_HS_EINVAL;
-    }
-
     if (ble_gap_master.op != BLE_GAP_OP_NULL) {
         return BLE_HS_EALREADY;
     }

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/e4c0c0ad/net/nimble/host/src/ble_gap_priv.h
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_gap_priv.h b/net/nimble/host/src/ble_gap_priv.h
index f0f3135..91bbd31 100644
--- a/net/nimble/host/src/ble_gap_priv.h
+++ b/net/nimble/host/src/ble_gap_priv.h
@@ -69,7 +69,7 @@ extern STATS_SECT_DECL(ble_gap_stats) ble_gap_stats;
 #define BLE_GAP_DISC_MODE_MAX               3
 
 int ble_gap_locked_by_cur_task(void);
-void ble_gap_rx_adv_report(struct ble_hs_adv *adv);
+void ble_gap_rx_adv_report(struct ble_gap_disc_desc *desc);
 int ble_gap_rx_conn_complete(struct hci_le_conn_complete *evt);
 void ble_gap_rx_disconn_complete(struct hci_disconn_complete *evt);
 void ble_gap_rx_update_complete(struct hci_le_conn_upd_complete *evt);

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/e4c0c0ad/net/nimble/host/src/ble_hs_adv.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_hs_adv.c b/net/nimble/host/src/ble_hs_adv.c
index 853d04a..83dd416 100644
--- a/net/nimble/host/src/ble_hs_adv.c
+++ b/net/nimble/host/src/ble_hs_adv.c
@@ -20,6 +20,7 @@
 #include <string.h>
 #include <errno.h>
 #include "nimble/ble.h"
+#include "host/ble_hs_adv.h"
 #include "ble_hs_priv.h"
 
 static int

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/e4c0c0ad/net/nimble/host/src/ble_hs_adv_priv.h
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_hs_adv_priv.h b/net/nimble/host/src/ble_hs_adv_priv.h
deleted file mode 100644
index 5b85374..0000000
--- a/net/nimble/host/src/ble_hs_adv_priv.h
+++ /dev/null
@@ -1,35 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you 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.
- */
-
-#ifndef H_BLE_HS_ADV_PRIV_
-#define H_BLE_HS_ADV_PRIV_
-
-#include "host/ble_hs_adv.h"
-
-struct ble_hs_adv {
-    uint8_t event_type;
-    uint8_t addr_type;
-    uint8_t length_data;
-    int8_t rssi;
-    uint8_t addr[6];
-    uint8_t *data;
-    struct ble_hs_adv_fields *fields;
-};
-
-#endif

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/e4c0c0ad/net/nimble/host/src/ble_hs_priv.h
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_hs_priv.h b/net/nimble/host/src/ble_hs_priv.h
index 8c0b47f..1eeb57f 100644
--- a/net/nimble/host/src/ble_hs_priv.h
+++ b/net/nimble/host/src/ble_hs_priv.h
@@ -27,9 +27,9 @@
 #include "ble_gap_priv.h"
 #include "ble_gatt_priv.h"
 #include "ble_hci_util_priv.h"
-#include "ble_hs_adv_priv.h"
 #include "ble_hs_atomic_priv.h"
 #include "ble_hs_conn_priv.h"
+#include "ble_hs_atomic_priv.h"
 #include "ble_hs_endian_priv.h"
 #include "ble_hs_startup_priv.h"
 #include "ble_l2cap_priv.h"

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/e4c0c0ad/net/nimble/host/src/ble_ibeacon.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_ibeacon.c b/net/nimble/host/src/ble_ibeacon.c
index db34dfb..06e203a 100644
--- a/net/nimble/host/src/ble_ibeacon.c
+++ b/net/nimble/host/src/ble_ibeacon.c
@@ -18,6 +18,7 @@
  */
 
 #include <string.h>
+#include "host/ble_hs_adv.h"
 #include "ble_hs_priv.h"
 
 #define BLE_IBEACON_MFG_DATA_SIZE       25

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/e4c0c0ad/net/nimble/host/src/host_hci.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/host_hci.c b/net/nimble/host/src/host_hci.c
index 4452dcc..29c71a1 100644
--- a/net/nimble/host/src/host_hci.c
+++ b/net/nimble/host/src/host_hci.c
@@ -25,6 +25,7 @@
 #include "nimble/hci_common.h"
 #include "nimble/hci_transport.h"
 #include "host/host_hci.h"
+#include "host/ble_gap.h"
 #include "ble_hs_priv.h"
 #include "host_dbg_priv.h"
 
@@ -44,6 +45,7 @@ static host_hci_le_event_fn host_hci_rx_le_adv_rpt;
 static host_hci_le_event_fn host_hci_rx_le_conn_upd_complete;
 static host_hci_le_event_fn host_hci_rx_le_lt_key_req;
 static host_hci_le_event_fn host_hci_rx_le_conn_parm_req;
+static host_hci_le_event_fn host_hci_rx_le_dir_adv_rpt;
 
 static uint16_t host_hci_buffer_sz;
 static uint8_t host_hci_max_pkts;
@@ -90,6 +92,7 @@ static const struct host_hci_le_event_dispatch_entry
     { BLE_HCI_LE_SUBEV_LT_KEY_REQ, host_hci_rx_le_lt_key_req },
     { BLE_HCI_LE_SUBEV_REM_CONN_PARM_REQ, host_hci_rx_le_conn_parm_req },
     { BLE_HCI_LE_SUBEV_ENH_CONN_COMPLETE, host_hci_rx_le_conn_complete },
+    { BLE_HCI_LE_SUBEV_DIRECT_ADV_RPT, host_hci_rx_le_dir_adv_rpt },
 };
 
 #define HOST_HCI_LE_EVENT_DISPATCH_SZ \
@@ -363,10 +366,11 @@ host_hci_le_adv_rpt_first_pass(uint8_t *data, int len,
 static int
 host_hci_rx_le_adv_rpt(uint8_t subevent, uint8_t *data, int len)
 {
-    struct ble_hs_adv adv;
+    struct ble_gap_disc_desc desc;
     uint8_t num_reports;
     int rssi_off;
     int data_off;
+    int suboff;
     int off;
     int rc;
     int i;
@@ -376,28 +380,93 @@ host_hci_rx_le_adv_rpt(uint8_t subevent, uint8_t *data, int len)
         return rc;
     }
 
+    /* Direct address fields not present in a standard advertising report. */
+    desc.direct_addr_type = BLE_GAP_ADDR_TYPE_NONE;
+    memset(desc.direct_addr, 0, sizeof desc.direct_addr);
+
     data_off = 0;
     for (i = 0; i < num_reports; i++) {
-        off = 2 + 0 * num_reports + i;
-        adv.event_type = data[2 + 0 * num_reports + i];
+        suboff = 0;
+
+        off = 2 + suboff * num_reports + i;
+        desc.event_type = data[off];
+        suboff++;
 
-        off = 2 + 1 * num_reports + i;
-        adv.addr_type = data[2 + 1 * num_reports + i];
+        off = 2 + suboff * num_reports + i;
+        desc.addr_type = data[off];
+        suboff++;
 
-        off = 2 + 2 * num_reports + i * 6;
-        memcpy(adv.addr, data + off, 6);
+        off = 2 + suboff * num_reports + i * 6;
+        memcpy(desc.addr, data + off, 6);
+        suboff += 6;
 
-        off = 2 + 8 * num_reports + i;
-        adv.length_data = data[off];
+        off = 2 + suboff * num_reports + i;
+        desc.length_data = data[off];
+        suboff++;
 
-        off = 2 + 9 * num_reports + data_off;
-        adv.data = data + off;
-        data_off += adv.length_data;
+        off = 2 + suboff * num_reports + data_off;
+        desc.data = data + off;
+        data_off += desc.length_data;
 
         off = rssi_off + 1 * i;
-        adv.rssi = data[off];
+        desc.rssi = data[off];
+
+        ble_gap_rx_adv_report(&desc);
+    }
+
+    return 0;
+}
+
+static int
+host_hci_rx_le_dir_adv_rpt(uint8_t subevent, uint8_t *data, int len)
+{
+    struct ble_gap_disc_desc desc;
+    uint8_t num_reports;
+    int suboff;
+    int off;
+    int i;
+
+    if (len < BLE_HCI_LE_ADV_DIRECT_RPT_LEN) {
+        return BLE_HS_ECONTROLLER;
+    }
+
+    num_reports = data[1];
+    if (len != 2 + num_reports * BLE_HCI_LE_ADV_DIRECT_RPT_SUB_LEN) {
+        return BLE_HS_ECONTROLLER;
+    }
+
+    /* Data fields not present in a direct advertising report. */
+    desc.data = NULL;
+    desc.fields = NULL;
+
+    for (i = 0; i < num_reports; i++) {
+        suboff = 0;
+
+        off = 2 + suboff * num_reports + i;
+        desc.event_type = data[off];
+        suboff++;
+
+        off = 2 + suboff * num_reports + i;
+        desc.addr_type = data[off];
+        suboff++;
+
+        off = 2 + suboff * num_reports + i * 6;
+        memcpy(desc.addr, data + off, 6);
+        suboff += 6;
+
+        off = 2 + suboff * num_reports + i;
+        desc.direct_addr_type = data[off];
+        suboff++;
+
+        off = 2 + suboff * num_reports + i * 6;
+        memcpy(desc.direct_addr, data + off, 6);
+        suboff += 6;
+
+        off = 2 + suboff * num_reports + i;
+        desc.rssi = data[off];
+        suboff++;
 
-        ble_gap_rx_adv_report(&adv);
+        ble_gap_rx_adv_report(&desc);
     }
 
     return 0;

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/e4c0c0ad/net/nimble/host/src/test/ble_gap_test.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/test/ble_gap_test.c b/net/nimble/host/src/test/ble_gap_test.c
index b8dbc82..a175dc9 100644
--- a/net/nimble/host/src/test/ble_gap_test.c
+++ b/net/nimble/host/src/test/ble_gap_test.c
@@ -22,6 +22,7 @@
 #include "testutil/testutil.h"
 #include "nimble/ble.h"
 #include "nimble/hci_common.h"
+#include "host/ble_hs_adv.h"
 #include "host/ble_hs_test.h"
 #include "ble_hs_test_util.h"
 
@@ -512,7 +513,7 @@ TEST_SUITE(ble_gap_test_suite_conn_wl)
 static int
 ble_gap_test_util_disc(uint8_t own_addr_type,
                        const struct ble_gap_disc_params *disc_params,
-                       struct ble_hs_adv *adv, int cmd_fail_idx,
+                       struct ble_gap_disc_desc *desc, int cmd_fail_idx,
                        uint8_t fail_status)
 {
     int rc;
@@ -526,7 +527,7 @@ ble_gap_test_util_disc(uint8_t own_addr_type,
     TEST_ASSERT(rc == BLE_HS_HCI_ERR(fail_status));
     if (rc == 0) {
         TEST_ASSERT(ble_gap_master_in_progress());
-        ble_gap_rx_adv_report(adv);
+        ble_gap_rx_adv_report(desc);
     } else {
         TEST_ASSERT(ble_gap_test_disc_status == -1);
     }
@@ -591,7 +592,7 @@ TEST_CASE(ble_gap_test_case_disc_good)
     int limited;
     int rc;
 
-    struct ble_hs_adv adv = {
+    struct ble_gap_disc_desc desc = {
         .event_type = BLE_HCI_ADV_TYPE_ADV_IND,
         .addr_type = BLE_ADDR_TYPE_PUBLIC,
         .length_data = 0,
@@ -610,7 +611,7 @@ TEST_CASE(ble_gap_test_case_disc_good)
 
     flags = BLE_HS_ADV_F_DISC_LTD;
     rc = ble_hs_adv_set_flat(BLE_HS_ADV_TYPE_FLAGS, 1, &flags,
-                             adv.data, &adv.length_data,
+                             desc.data, &desc.length_data,
                              sizeof adv_data);
     TEST_ASSERT_FATAL(rc == 0);
 
@@ -621,7 +622,7 @@ TEST_CASE(ble_gap_test_case_disc_good)
     for (limited = 0; limited <= 1; limited++) {
         disc_params.passive = passive;
         disc_params.limited = limited;
-        ble_gap_test_util_disc(own_addr_type, &disc_params, &adv, -1, 0);
+        ble_gap_test_util_disc(own_addr_type, &disc_params, &desc, -1, 0);
 
         TEST_ASSERT(ble_gap_master_in_progress());
         TEST_ASSERT(ble_gap_test_disc_event == BLE_GAP_EVENT_DISC_SUCCESS);
@@ -632,7 +633,7 @@ TEST_CASE(ble_gap_test_case_disc_good)
                     BLE_ADDR_TYPE_PUBLIC);
         TEST_ASSERT(ble_gap_test_disc_desc.length_data == 3);
         TEST_ASSERT(ble_gap_test_disc_desc.rssi == 0);
-        TEST_ASSERT(memcmp(ble_gap_test_disc_desc.addr, adv.addr, 6) == 0);
+        TEST_ASSERT(memcmp(ble_gap_test_disc_desc.addr, desc.addr, 6) == 0);
         TEST_ASSERT(ble_gap_test_disc_arg == NULL);
     }
 }
@@ -640,7 +641,7 @@ TEST_CASE(ble_gap_test_case_disc_good)
 TEST_CASE(ble_gap_test_case_disc_ltd_mismatch)
 {
     int rc;
-    struct ble_hs_adv adv = {
+    struct ble_gap_disc_desc desc = {
         .event_type = BLE_HCI_ADV_TYPE_ADV_IND,
         .addr_type = BLE_ADDR_TYPE_PUBLIC,
         .length_data = 0,
@@ -661,7 +662,7 @@ TEST_CASE(ble_gap_test_case_disc_ltd_mismatch)
         .filter_duplicates = 0,
     };
 
-    rc = ble_gap_test_util_disc(BLE_ADDR_TYPE_PUBLIC, &disc_params, &adv,
+    rc = ble_gap_test_util_disc(BLE_ADDR_TYPE_PUBLIC, &disc_params, &desc,
                                 -1, 0);
     TEST_ASSERT(rc == 0);
     TEST_ASSERT(ble_gap_master_in_progress());
@@ -673,9 +674,9 @@ TEST_CASE(ble_gap_test_case_disc_ltd_mismatch)
     rc = ble_hs_test_util_disc_cancel(0);
     TEST_ASSERT(rc == 0);
 
-    adv.data[2] = BLE_HS_ADV_F_DISC_LTD;
+    desc.data[2] = BLE_HS_ADV_F_DISC_LTD;
     disc_params.limited = 0;
-    rc = ble_gap_test_util_disc(BLE_ADDR_TYPE_PUBLIC, &disc_params, &adv,
+    rc = ble_gap_test_util_disc(BLE_ADDR_TYPE_PUBLIC, &disc_params, &desc,
                                 -1, 0);
     TEST_ASSERT(rc == 0);
     TEST_ASSERT(ble_gap_master_in_progress());
@@ -692,7 +693,7 @@ TEST_CASE(ble_gap_test_case_disc_hci_fail)
     int limited;
     int rc;
 
-    struct ble_hs_adv adv = {
+    struct ble_gap_disc_desc desc = {
         .event_type = BLE_HCI_ADV_TYPE_ADV_IND,
         .addr_type = BLE_ADDR_TYPE_PUBLIC,
         .length_data = 0,
@@ -714,7 +715,7 @@ TEST_CASE(ble_gap_test_case_disc_hci_fail)
 
         for (fail_idx = 0; fail_idx < 2; fail_idx++) {
             rc = ble_gap_test_util_disc(BLE_ADDR_TYPE_PUBLIC, &disc_params,
-                                        &adv, fail_idx, BLE_ERR_UNSUPPORTED);
+                                        &desc, fail_idx, BLE_ERR_UNSUPPORTED);
             TEST_ASSERT(rc == BLE_HS_HCI_ERR(BLE_ERR_UNSUPPORTED));
             TEST_ASSERT(!ble_gap_master_in_progress());
         }
@@ -725,6 +726,7 @@ static void
 ble_gap_test_util_disc_dflts_once(int limited)
 {
     struct ble_gap_disc_params params;
+    uint16_t exp_window;
     uint16_t exp_itvl;
     int rc;
 
@@ -739,14 +741,16 @@ ble_gap_test_util_disc_dflts_once(int limited)
 
     if (limited) {
         exp_itvl = BLE_GAP_LIM_DISC_SCAN_INT;
+        exp_window = BLE_GAP_LIM_DISC_SCAN_WINDOW;
     } else {
-        exp_itvl = BLE_GAP_SCAN_SLOW_INTERVAL1;
+        exp_itvl = BLE_GAP_SCAN_FAST_INTERVAL_MIN;
+        exp_window = BLE_GAP_SCAN_FAST_WINDOW;
     }
     ble_gap_test_util_verify_tx_set_scan_params(
         BLE_ADDR_TYPE_PUBLIC,
         BLE_HCI_SCAN_TYPE_ACTIVE,
         exp_itvl,
-        BLE_GAP_SCAN_SLOW_WINDOW1,
+        exp_window,
         BLE_HCI_SCAN_FILT_NO_WL);
 
     ble_gap_test_util_verify_tx_scan_enable(1, 0);

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/e4c0c0ad/net/nimble/host/src/test/ble_hs_adv_test.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/test/ble_hs_adv_test.c b/net/nimble/host/src/test/ble_hs_adv_test.c
index 1cd4370..3a78505 100644
--- a/net/nimble/host/src/test/ble_hs_adv_test.c
+++ b/net/nimble/host/src/test/ble_hs_adv_test.c
@@ -22,6 +22,7 @@
 #include <string.h>
 #include "testutil/testutil.h"
 #include "nimble/hci_common.h"
+#include "host/ble_hs_adv.h"
 #include "host/ble_hs_test.h"
 #include "host/host_hci.h"
 #include "ble_hs_test_util.h"

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/e4c0c0ad/net/nimble/host/src/test/ble_hs_conn_test.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/test/ble_hs_conn_test.c b/net/nimble/host/src/test/ble_hs_conn_test.c
index 50d70c9..ef643d7 100644
--- a/net/nimble/host/src/test/ble_hs_conn_test.c
+++ b/net/nimble/host/src/test/ble_hs_conn_test.c
@@ -22,6 +22,7 @@
 #include <string.h>
 #include "testutil/testutil.h"
 #include "nimble/hci_common.h"
+#include "host/ble_hs_adv.h"
 #include "host/ble_hs_test.h"
 #include "host/host_hci.h"
 #include "ble_hs_test_util.h"

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/e4c0c0ad/net/nimble/host/src/test/ble_hs_test_util.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/test/ble_hs_test_util.c b/net/nimble/host/src/test/ble_hs_test_util.c
index f2f334f..1a08801 100644
--- a/net/nimble/host/src/test/ble_hs_test_util.c
+++ b/net/nimble/host/src/test/ble_hs_test_util.c
@@ -24,6 +24,7 @@
 #include "nimble/ble.h"
 #include "nimble/hci_common.h"
 #include "nimble/hci_transport.h"
+#include "host/ble_hs_adv.h"
 #include "host/host_hci.h"
 #include "ble_hs_test_util.h"
 

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/e4c0c0ad/net/nimble/include/nimble/hci_common.h
----------------------------------------------------------------------
diff --git a/net/nimble/include/nimble/hci_common.h b/net/nimble/include/nimble/hci_common.h
index 0292be5..d5c8743 100644
--- a/net/nimble/include/nimble/hci_common.h
+++ b/net/nimble/include/nimble/hci_common.h
@@ -515,6 +515,9 @@
 #define BLE_HCI_LE_ADV_RPT_NUM_RPTS_MIN     (1)
 #define BLE_HCI_LE_ADV_RPT_NUM_RPTS_MAX     (0x19)
 
+/* Length of each record in an LE direct advertising report event. */
+#define BLE_HCI_LE_ADV_DIRECT_RPT_SUB_LEN   (16)
+
 /* LE connection update complete event (sub event 0x03) */
 #define BLE_HCI_LE_CONN_UPD_LEN             (10)