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/11 23:50:17 UTC

[27/50] [abbrv] incubator-mynewt-core git commit: BLE Host - Add missing fields to ble_gap_conn_desc

BLE Host - Add missing fields to ble_gap_conn_desc

* role
* master_clock_accuracy


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

Branch: refs/heads/ble_hs_api
Commit: 46801abffb80666a2da503a5bf1b3ea9251f4e2c
Parents: 9fd7889
Author: Christopher Collins <cc...@apache.org>
Authored: Fri Jun 24 15:10:27 2016 -0700
Committer: Christopher Collins <cc...@apache.org>
Committed: Mon Jul 11 16:43:32 2016 -0700

----------------------------------------------------------------------
 apps/bletiny/src/cmd.c                  |   2 +-
 apps/bletiny/src/main.c                 |   2 +-
 net/nimble/host/include/host/ble_gap.h  |   7 +-
 net/nimble/host/src/ble_gap.c           |  10 +-
 net/nimble/host/src/ble_hs_conn_priv.h  |   1 +
 net/nimble/host/src/test/ble_gap_test.c | 155 ++++++++++++++++++++++-----
 6 files changed, 149 insertions(+), 28 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/46801abf/apps/bletiny/src/cmd.c
----------------------------------------------------------------------
diff --git a/apps/bletiny/src/cmd.c b/apps/bletiny/src/cmd.c
index b735094..d6e824d 100644
--- a/apps/bletiny/src/cmd.c
+++ b/apps/bletiny/src/cmd.c
@@ -1047,7 +1047,7 @@ cmd_show_conn(int argc, char **argv)
     for (i = 0; i < bletiny_num_conns; i++) {
         conn = bletiny_conns + i;
 
-        rc = ble_gap_find_conn(conn->handle, &conn_desc);
+        rc = ble_gap_conn_find(conn->handle, &conn_desc);
         if (rc == 0) {
             print_conn_desc(&conn_desc);
         }

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/46801abf/apps/bletiny/src/main.c
----------------------------------------------------------------------
diff --git a/apps/bletiny/src/main.c b/apps/bletiny/src/main.c
index d8c43f2..764eb00 100755
--- a/apps/bletiny/src/main.c
+++ b/apps/bletiny/src/main.c
@@ -1408,7 +1408,7 @@ bletiny_sec_restart(uint16_t conn_handle,
 
     if (ltk == NULL) {
         /* The user is requesting a store lookup. */
-        rc = ble_gap_find_conn(conn_handle, &desc);
+        rc = ble_gap_conn_find(conn_handle, &desc);
         if (rc != 0) {
             return rc;
         }

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/46801abf/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 48ca957..f2adaf5 100644
--- a/net/nimble/host/include/host/ble_gap.h
+++ b/net/nimble/host/include/host/ble_gap.h
@@ -95,6 +95,9 @@ struct hci_conn_update;
 #define BLE_GAP_ADDR_TYPE_WL                0xff
 #define BLE_GAP_ADDR_TYPE_NONE              0xfe
 
+#define BLE_GAP_ROLE_MASTER                 0
+#define BLE_GAP_ROLE_SLAVE                  1
+
 #define BLE_GAP_EVENT_CONNECT               0
 #define BLE_GAP_EVENT_DISCONNECT            1
 #define BLE_GAP_EVENT_CONN_CANCEL           2
@@ -158,6 +161,8 @@ struct ble_gap_conn_desc {
     uint8_t peer_id_addr_type;
     uint8_t our_id_addr_type;
     uint8_t our_ota_addr_type;
+    uint8_t role;
+    uint8_t master_clock_accuracy;
 };
 
 struct ble_gap_conn_params {
@@ -286,7 +291,7 @@ struct ble_gap_white_entry {
     uint8_t addr[6];
 };
 
-int ble_gap_find_conn(uint16_t handle, struct ble_gap_conn_desc *out_desc);
+int ble_gap_conn_find(uint16_t handle, struct ble_gap_conn_desc *out_desc);
 
 int ble_gap_adv_start(uint8_t own_addr_type, uint8_t peer_addr_type,
                       const uint8_t *peer_addr, int32_t duration_ms,

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/46801abf/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 14b334d..04f9489 100644
--- a/net/nimble/host/src/ble_gap.c
+++ b/net/nimble/host/src/ble_gap.c
@@ -300,7 +300,14 @@ ble_gap_fill_conn_desc(struct ble_hs_conn *conn,
     desc->conn_itvl = conn->bhc_itvl;
     desc->conn_latency = conn->bhc_latency;
     desc->supervision_timeout = conn->bhc_supervision_timeout;
+    desc->master_clock_accuracy = conn->bhc_master_clock_accuracy;
     desc->sec_state = conn->bhc_sec_state;
+
+    if (conn->bhc_flags & BLE_HS_CONN_F_MASTER) {
+        desc->role = BLE_GAP_ROLE_MASTER;
+    } else {
+        desc->role = BLE_GAP_ROLE_SLAVE;
+    }
 }
 
 static void
@@ -347,7 +354,7 @@ ble_gap_find_snapshot(uint16_t handle, struct ble_gap_snapshot *snap)
  *                                  connection was found.
  */
 int
-ble_gap_find_conn(uint16_t handle, struct ble_gap_conn_desc *out_desc)
+ble_gap_conn_find(uint16_t handle, struct ble_gap_conn_desc *out_desc)
 {
     struct ble_hs_conn *conn;
 
@@ -985,6 +992,7 @@ ble_gap_rx_conn_complete(struct hci_le_conn_complete *evt)
     conn->bhc_itvl = evt->conn_itvl;
     conn->bhc_latency = evt->conn_latency;
     conn->bhc_supervision_timeout = evt->supervision_timeout;
+    conn->bhc_master_clock_accuracy = evt->master_clk_acc;
     if (evt->role == BLE_HCI_LE_CONN_COMPLETE_ROLE_MASTER) {
         conn->bhc_flags |= BLE_HS_CONN_F_MASTER;
         conn->bhc_cb = ble_gap_master.conn.cb;

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/46801abf/net/nimble/host/src/ble_hs_conn_priv.h
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_hs_conn_priv.h b/net/nimble/host/src/ble_hs_conn_priv.h
index 36b483d..3ff7f76 100644
--- a/net/nimble/host/src/ble_hs_conn_priv.h
+++ b/net/nimble/host/src/ble_hs_conn_priv.h
@@ -45,6 +45,7 @@ struct ble_hs_conn {
     uint16_t bhc_itvl;
     uint16_t bhc_latency;
     uint16_t bhc_supervision_timeout;
+    uint8_t bhc_master_clock_accuracy;
 
     ble_hs_conn_flags_t bhc_flags;
 

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/46801abf/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 5c8489f..dbda665 100644
--- a/net/nimble/host/src/test/ble_gap_test.c
+++ b/net/nimble/host/src/test/ble_gap_test.c
@@ -436,7 +436,7 @@ ble_gap_test_util_wl_set(struct ble_gap_white_entry *white_list,
     }
 }
 
-TEST_CASE(ble_gap_test_case_conn_wl_bad_args)
+TEST_CASE(ble_gap_test_case_wl_bad_args)
 {
     int rc;
 
@@ -468,7 +468,7 @@ TEST_CASE(ble_gap_test_case_conn_wl_bad_args)
     TEST_ASSERT(rc == BLE_HS_EBUSY);
 }
 
-TEST_CASE(ble_gap_test_case_conn_wl_ctlr_fail)
+TEST_CASE(ble_gap_test_case_wl_ctlr_fail)
 {
     int i;
 
@@ -486,7 +486,7 @@ TEST_CASE(ble_gap_test_case_conn_wl_ctlr_fail)
     }
 }
 
-TEST_CASE(ble_gap_test_case_conn_wl_good)
+TEST_CASE(ble_gap_test_case_wl_good)
 {
     struct ble_gap_white_entry white_list[] = {
         { BLE_ADDR_TYPE_PUBLIC, { 1, 2, 3, 4, 5, 6 } },
@@ -499,11 +499,11 @@ TEST_CASE(ble_gap_test_case_conn_wl_good)
     ble_gap_test_util_wl_set(white_list, white_list_count, 0, 0);
 }
 
-TEST_SUITE(ble_gap_test_suite_conn_wl)
+TEST_SUITE(ble_gap_test_suite_wl)
 {
-    ble_gap_test_case_conn_wl_good();
-    ble_gap_test_case_conn_wl_bad_args();
-    ble_gap_test_case_conn_wl_ctlr_fail();
+    ble_gap_test_case_wl_good();
+    ble_gap_test_case_wl_bad_args();
+    ble_gap_test_case_wl_ctlr_fail();
 }
 
 /*****************************************************************************
@@ -1088,6 +1088,112 @@ TEST_SUITE(ble_gap_test_suite_conn_terminate)
 }
 
 /*****************************************************************************
+ * $conn find                                                                *
+ *****************************************************************************/
+
+TEST_CASE(ble_gap_test_case_conn_find)
+{
+
+    struct ble_gap_conn_desc desc;
+    struct ble_hs_conn *conn;
+    int rc;
+
+    /*** We are master; public addresses. */
+    ble_gap_test_util_init();
+
+    ble_hs_test_util_create_rpa_conn(8,
+                                     BLE_ADDR_TYPE_PUBLIC,
+                                     ((uint8_t[6]){0,0,0,0,0,0}),
+                                     BLE_ADDR_TYPE_PUBLIC,
+                                     ((uint8_t[6]){2,3,4,5,6,7}),
+                                     ((uint8_t[6]){0,0,0,0,0,0}),
+                                     ble_gap_test_util_connect_cb,
+                                     NULL);
+
+    rc = ble_gap_conn_find(8, &desc);
+    TEST_ASSERT_FATAL(rc == 0);
+    TEST_ASSERT(desc.conn_handle == 8);
+    TEST_ASSERT(desc.our_id_addr_type == BLE_ADDR_TYPE_PUBLIC);
+    TEST_ASSERT(desc.our_ota_addr_type == BLE_ADDR_TYPE_PUBLIC);
+    TEST_ASSERT(desc.peer_ota_addr_type == BLE_ADDR_TYPE_PUBLIC);
+    TEST_ASSERT(desc.role == BLE_GAP_ROLE_MASTER);
+    TEST_ASSERT(memcmp(desc.our_ota_addr, g_dev_addr, 6) == 0);
+    TEST_ASSERT(memcmp(desc.our_id_addr, g_dev_addr, 6) == 0);
+    TEST_ASSERT(memcmp(desc.peer_ota_addr,
+                       ((uint8_t[6]){2,3,4,5,6,7}), 6) == 0);
+    TEST_ASSERT(memcmp(desc.peer_id_addr,
+                       ((uint8_t[6]){2,3,4,5,6,7}), 6) == 0);
+    TEST_ASSERT(desc.conn_itvl == BLE_GAP_INITIAL_CONN_ITVL_MAX);
+    TEST_ASSERT(desc.conn_latency == BLE_GAP_INITIAL_CONN_LATENCY);
+    TEST_ASSERT(desc.supervision_timeout ==
+                BLE_GAP_INITIAL_SUPERVISION_TIMEOUT);
+    TEST_ASSERT(desc.master_clock_accuracy == 0);
+    TEST_ASSERT(!desc.sec_state.encrypted);
+    TEST_ASSERT(!desc.sec_state.authenticated);
+    TEST_ASSERT(!desc.sec_state.bonded);
+
+    /*** Swap roles. */
+    ble_hs_lock();
+    conn = ble_hs_conn_find(8);
+    conn->bhc_flags &= ~BLE_HS_CONN_F_MASTER;
+    ble_hs_unlock();
+
+    rc = ble_gap_conn_find(8, &desc);
+    TEST_ASSERT_FATAL(rc == 0);
+    TEST_ASSERT(desc.role == BLE_GAP_ROLE_SLAVE);
+
+    /*** We are master; RPAs. */
+    ble_gap_test_util_init();
+
+    ble_hs_test_util_create_rpa_conn(54,
+                                     BLE_ADDR_TYPE_RPA_PUB_DEFAULT,
+                                     ((uint8_t[6]){0x40,1,2,3,4,5}),
+                                     BLE_ADDR_TYPE_RPA_RND_DEFAULT,
+                                     ((uint8_t[6]){3,4,5,6,7,8}),
+                                     ((uint8_t[6]){0x50,1,2,3,4,5}),
+                                     ble_gap_test_util_connect_cb,
+                                     NULL);
+
+    rc = ble_gap_conn_find(54, &desc);
+    TEST_ASSERT_FATAL(rc == 0);
+    TEST_ASSERT(desc.conn_handle == 54);
+    TEST_ASSERT(desc.our_id_addr_type == BLE_ADDR_TYPE_PUBLIC);
+    TEST_ASSERT(desc.our_ota_addr_type == BLE_ADDR_TYPE_RPA_PUB_DEFAULT);
+    TEST_ASSERT(desc.peer_ota_addr_type == BLE_ADDR_TYPE_RPA_RND_DEFAULT);
+    TEST_ASSERT(desc.role == BLE_GAP_ROLE_MASTER);
+    TEST_ASSERT(memcmp(desc.our_ota_addr,
+                       ((uint8_t[6]){0x40,1,2,3,4,5}), 6) == 0);
+    TEST_ASSERT(memcmp(desc.our_id_addr, g_dev_addr, 6) == 0);
+    TEST_ASSERT(memcmp(desc.peer_ota_addr,
+                       ((uint8_t[6]){0x50,1,2,3,4,5}), 6) == 0);
+    TEST_ASSERT(memcmp(desc.peer_id_addr,
+                       ((uint8_t[6]){3,4,5,6,7,8}), 6) == 0);
+    TEST_ASSERT(desc.conn_itvl == BLE_GAP_INITIAL_CONN_ITVL_MAX);
+    TEST_ASSERT(desc.conn_latency == BLE_GAP_INITIAL_CONN_LATENCY);
+    TEST_ASSERT(desc.supervision_timeout ==
+                BLE_GAP_INITIAL_SUPERVISION_TIMEOUT);
+    TEST_ASSERT(desc.master_clock_accuracy == 0);
+    TEST_ASSERT(!desc.sec_state.encrypted);
+    TEST_ASSERT(!desc.sec_state.authenticated);
+    TEST_ASSERT(!desc.sec_state.bonded);
+
+    /*** Swap roles. */
+    ble_hs_lock();
+    conn = ble_hs_conn_find(54);
+    conn->bhc_flags &= ~BLE_HS_CONN_F_MASTER;
+    ble_hs_unlock();
+
+    rc = ble_gap_conn_find(54, &desc);
+    TEST_ASSERT_FATAL(rc == 0);
+    TEST_ASSERT(desc.role == BLE_GAP_ROLE_SLAVE);
+}
+
+TEST_SUITE(ble_gap_test_suite_conn_find)
+{
+    ble_gap_test_case_conn_find();
+}
+
+/*****************************************************************************
  * $advertise                                                                *
  *****************************************************************************/
 
@@ -1193,7 +1299,7 @@ ble_gap_test_util_adv(uint8_t own_addr_type, uint8_t peer_addr_type,
     }
 }
 
-TEST_CASE(ble_gap_test_case_conn_adv_bad_args)
+TEST_CASE(ble_gap_test_case_adv_bad_args)
 {
     struct ble_gap_adv_params adv_params;
     uint8_t peer_addr[6] = { 1, 2, 3, 4, 5, 6 };
@@ -1328,7 +1434,7 @@ TEST_CASE(ble_gap_test_case_adv_dflt_params)
     }
 }
 
-TEST_CASE(ble_gap_test_case_conn_adv_good)
+TEST_CASE(ble_gap_test_case_adv_good)
 {
     uint8_t peer_addr[6] = { 1, 2, 3, 4, 5, 6 };
     int d;
@@ -1352,7 +1458,7 @@ TEST_CASE(ble_gap_test_case_conn_adv_good)
     }
 }
 
-TEST_CASE(ble_gap_test_case_conn_adv_ctlr_fail)
+TEST_CASE(ble_gap_test_case_adv_ctlr_fail)
 {
     uint8_t peer_addr[6] = { 1, 2, 3, 4, 5, 6 };
     int d;
@@ -1372,7 +1478,7 @@ TEST_CASE(ble_gap_test_case_conn_adv_ctlr_fail)
     }
 }
 
-TEST_CASE(ble_gap_test_case_conn_adv_hci_fail)
+TEST_CASE(ble_gap_test_case_adv_hci_fail)
 {
     uint8_t peer_addr[6] = { 1, 2, 3, 4, 5, 6 };
     int num_hci_cmds;
@@ -1400,13 +1506,13 @@ TEST_CASE(ble_gap_test_case_conn_adv_hci_fail)
     }
 }
 
-TEST_SUITE(ble_gap_test_suite_conn_adv)
+TEST_SUITE(ble_gap_test_suite_adv)
 {
-    ble_gap_test_case_conn_adv_bad_args();
+    ble_gap_test_case_adv_bad_args();
     ble_gap_test_case_adv_dflt_params();
-    ble_gap_test_case_conn_adv_good();
-    ble_gap_test_case_conn_adv_ctlr_fail();
-    ble_gap_test_case_conn_adv_hci_fail();
+    ble_gap_test_case_adv_good();
+    ble_gap_test_case_adv_ctlr_fail();
+    ble_gap_test_case_adv_hci_fail();
 }
 
 /*****************************************************************************
@@ -1439,7 +1545,7 @@ ble_gap_test_util_stop_adv(uint8_t peer_addr_type, const uint8_t *peer_addr,
     ble_gap_test_util_verify_tx_adv_enable(0);
 }
 
-TEST_CASE(ble_gap_test_case_conn_stop_adv_good)
+TEST_CASE(ble_gap_test_case_stop_adv_good)
 {
     uint8_t peer_addr[6] = { 1, 2, 3, 4, 5, 6 };
     int d;
@@ -1458,7 +1564,7 @@ TEST_CASE(ble_gap_test_case_conn_stop_adv_good)
     }
 }
 
-TEST_CASE(ble_gap_test_case_conn_stop_adv_hci_fail)
+TEST_CASE(ble_gap_test_case_stop_adv_hci_fail)
 {
     uint8_t peer_addr[6] = { 1, 2, 3, 4, 5, 6 };
     int d;
@@ -1477,10 +1583,10 @@ TEST_CASE(ble_gap_test_case_conn_stop_adv_hci_fail)
     }
 }
 
-TEST_SUITE(ble_gap_test_suite_conn_stop_adv)
+TEST_SUITE(ble_gap_test_suite_stop_adv)
 {
-    ble_gap_test_case_conn_stop_adv_good();
-    ble_gap_test_case_conn_stop_adv_hci_fail();
+    ble_gap_test_case_stop_adv_good();
+    ble_gap_test_case_stop_adv_hci_fail();
 }
 
 /*****************************************************************************
@@ -2061,13 +2167,14 @@ TEST_SUITE(ble_gap_test_suite_update_conn)
 int
 ble_gap_test_all(void)
 {
-    ble_gap_test_suite_conn_wl();
+    ble_gap_test_suite_wl();
     ble_gap_test_suite_disc();
     ble_gap_test_suite_conn_dir();
     ble_gap_test_suite_conn_cancel();
     ble_gap_test_suite_conn_terminate();
-    ble_gap_test_suite_conn_adv();
-    ble_gap_test_suite_conn_stop_adv();
+    ble_gap_test_suite_conn_find();
+    ble_gap_test_suite_adv();
+    ble_gap_test_suite_stop_adv();
     ble_gap_test_suite_update_conn();
 
     return tu_any_failed;