nimble/privacy: fix set private address timeout

Actually send the hci command after building it.

SET_RPA_TMO should be expected only when test uses RPA and privacy has
not yet been enabled. The Bluetooth stack remembers that privacy is
enabled and does not send SET_RPA_TMO every time. For test purpose
let's track privacy state in here.


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/34d34e1d
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/34d34e1d
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/34d34e1d

Branch: refs/heads/develop
Commit: 34d34e1d661643a446b542492cd775cb01cf54cb
Parents: f1a94d2
Author: Michał Narajowski <[email protected]>
Authored: Tue Jan 10 13:35:23 2017 +0100
Committer: Michał Narajowski <[email protected]>
Committed: Wed Jan 18 14:51:40 2017 +0100

----------------------------------------------------------------------
 net/nimble/host/src/ble_hs_pvcy.c           |  6 ++-
 net/nimble/host/test/src/ble_hs_test_util.c | 52 ++++++++++++++++++------
 2 files changed, 45 insertions(+), 13 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/34d34e1d/net/nimble/host/src/ble_hs_pvcy.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_hs_pvcy.c 
b/net/nimble/host/src/ble_hs_pvcy.c
index 8c8552d..3a6d974 100644
--- a/net/nimble/host/src/ble_hs_pvcy.c
+++ b/net/nimble/host/src/ble_hs_pvcy.c
@@ -39,7 +39,11 @@ ble_hs_pvcy_set_addr_timeout(uint16_t timeout)
     rc = ble_hs_hci_cmd_build_set_resolv_priv_addr_timeout(
             timeout, buf, sizeof(buf));
 
-    return rc;
+    if (rc != 0) {
+        return rc;
+    }
+
+    return ble_hs_hci_cmd_tx(buf, NULL, 0, NULL);
 }
 
 static int

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/34d34e1d/net/nimble/host/test/src/ble_hs_test_util.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/test/src/ble_hs_test_util.c 
b/net/nimble/host/test/src/ble_hs_test_util.c
index 1470fc6..1144431 100644
--- a/net/nimble/host/test/src/ble_hs_test_util.c
+++ b/net/nimble/host/test/src/ble_hs_test_util.c
@@ -614,20 +614,48 @@ ble_hs_test_util_disc(uint8_t own_addr_type, int32_t 
duration_ms,
                       ble_gap_event_fn *cb, void *cb_arg, int fail_idx,
                       uint8_t fail_status)
 {
+    static bool privacy_enabled;
     int rc;
 
-    ble_hs_test_util_set_ack_seq(((struct ble_hs_test_util_phony_ack[]) {
-        {
-            BLE_HS_TEST_UTIL_LE_OPCODE(BLE_HCI_OCF_LE_SET_SCAN_PARAMS),
-            ble_hs_test_util_exp_hci_status(0, fail_idx, fail_status),
-        },
-        {
-            BLE_HS_TEST_UTIL_LE_OPCODE(BLE_HCI_OCF_LE_SET_SCAN_ENABLE),
-            ble_hs_test_util_exp_hci_status(1, fail_idx, fail_status),
-        },
-
-        { 0 }
-    }));
+    /*
+     * SET_RPA_TMO should be expected only when test uses RPA and privacy has
+     * not yet been enabled. The Bluetooth stack remembers that privacy is
+     * enabled and does not send SET_RPA_TMO every time. For test purpose
+     * let's track privacy state in here.
+     */
+    if ((own_addr_type == BLE_ADDR_TYPE_RPA_PUB_DEFAULT ||
+         own_addr_type == BLE_ADDR_TYPE_RPA_RND_DEFAULT) && !privacy_enabled) {
+        privacy_enabled = true;
+        ble_hs_test_util_set_ack_seq(((struct ble_hs_test_util_phony_ack[]) {
+            {
+                BLE_HS_TEST_UTIL_LE_OPCODE(BLE_HCI_OCF_LE_SET_RPA_TMO),
+                ble_hs_test_util_exp_hci_status(0, fail_idx, fail_status),
+            },
+            {
+                BLE_HS_TEST_UTIL_LE_OPCODE(BLE_HCI_OCF_LE_SET_SCAN_PARAMS),
+                ble_hs_test_util_exp_hci_status(1, fail_idx, fail_status),
+            },
+            {
+                BLE_HS_TEST_UTIL_LE_OPCODE(BLE_HCI_OCF_LE_SET_SCAN_ENABLE),
+                ble_hs_test_util_exp_hci_status(2, fail_idx, fail_status),
+            },
+
+            { 0 }
+        }));
+    } else {
+        ble_hs_test_util_set_ack_seq(((struct ble_hs_test_util_phony_ack[]) {
+            {
+                BLE_HS_TEST_UTIL_LE_OPCODE(BLE_HCI_OCF_LE_SET_SCAN_PARAMS),
+                ble_hs_test_util_exp_hci_status(0, fail_idx, fail_status),
+            },
+            {
+                BLE_HS_TEST_UTIL_LE_OPCODE(BLE_HCI_OCF_LE_SET_SCAN_ENABLE),
+                ble_hs_test_util_exp_hci_status(1, fail_idx, fail_status),
+            },
+
+            { 0 }
+        }));
+    }
 
     rc = ble_gap_disc(own_addr_type, duration_ms, disc_params,
                       cb, cb_arg);

Reply via email to