mynewt-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ccoll...@apache.org
Subject incubator-mynewt-core git commit: MYNEWT-487 BLE Host - Execute GATT proc cb on tmo.
Date Fri, 02 Dec 2016 20:51:38 GMT
Repository: incubator-mynewt-core
Updated Branches:
  refs/heads/develop 35e11e672 -> ec16344c9


MYNEWT-487 BLE Host - Execute GATT proc cb on tmo.


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

Branch: refs/heads/develop
Commit: ec16344c9dcfb4de487a172a8335cbc0341d3723
Parents: 35e11e6
Author: Christopher Collins <ccollins@apache.org>
Authored: Fri Dec 2 12:50:52 2016 -0800
Committer: Christopher Collins <ccollins@apache.org>
Committed: Fri Dec 2 12:51:30 2016 -0800

----------------------------------------------------------------------
 net/nimble/host/src/ble_gattc.c                 | 215 ++++++++++++++++++-
 net/nimble/host/test/src/ble_gatt_conn_test.c   | 177 ++++++++-------
 net/nimble/host/test/src/ble_gatt_disc_s_test.c |   4 +
 3 files changed, 318 insertions(+), 78 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/ec16344c/net/nimble/host/src/ble_gattc.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_gattc.c b/net/nimble/host/src/ble_gattc.c
index 857530b..8bbe0b1 100644
--- a/net/nimble/host/src/ble_gattc.c
+++ b/net/nimble/host/src/ble_gattc.c
@@ -86,7 +86,7 @@
 #define BLE_GATT_OP_WRITE_LONG                  12
 #define BLE_GATT_OP_WRITE_RELIABLE              13
 #define BLE_GATT_OP_INDICATE                    14
-#define BLE_GATT_OP_MAX                         15
+#define BLE_GATT_OP_CNT                         15
 
 /** Procedure stalled due to resource exhaustion. */
 #define BLE_GATTC_PROC_F_STALLED                0x01
@@ -233,7 +233,7 @@ static ble_gattc_err_fn ble_gattc_write_long_err;
 static ble_gattc_err_fn ble_gattc_write_reliable_err;
 static ble_gattc_err_fn ble_gattc_indicate_err;
 
-static ble_gattc_err_fn * const ble_gattc_err_dispatch[BLE_GATT_OP_MAX] = {
+static ble_gattc_err_fn * const ble_gattc_err_dispatch[BLE_GATT_OP_CNT] = {
     [BLE_GATT_OP_MTU]               = ble_gattc_mtu_err,
     [BLE_GATT_OP_DISC_ALL_SVCS]     = ble_gattc_disc_all_svcs_err,
     [BLE_GATT_OP_DISC_SVC_UUID]     = ble_gattc_disc_svc_uuid_err,
@@ -251,6 +251,10 @@ static ble_gattc_err_fn * const ble_gattc_err_dispatch[BLE_GATT_OP_MAX]
= {
     [BLE_GATT_OP_INDICATE]          = ble_gattc_indicate_err,
 };
 
+/**
+ * Resume functions - these handle periodic retries of procedures that have
+ * stalled due to memory exhaustion.
+ */
 typedef int ble_gattc_resume_fn(struct ble_gattc_proc *proc);
 
 static ble_gattc_resume_fn ble_gattc_disc_all_svcs_resume;
@@ -264,7 +268,7 @@ static ble_gattc_resume_fn ble_gattc_write_long_resume;
 static ble_gattc_resume_fn ble_gattc_write_reliable_resume;
 
 static ble_gattc_resume_fn * const
-ble_gattc_resume_dispatch[BLE_GATT_OP_MAX] = {
+ble_gattc_resume_dispatch[BLE_GATT_OP_CNT] = {
     [BLE_GATT_OP_MTU]               = NULL,
     [BLE_GATT_OP_DISC_ALL_SVCS]     = ble_gattc_disc_all_svcs_resume,
     [BLE_GATT_OP_DISC_SVC_UUID]     = ble_gattc_disc_svc_uuid_resume,
@@ -283,6 +287,47 @@ ble_gattc_resume_dispatch[BLE_GATT_OP_MAX] = {
 };
 
 /**
+ * Timeout functions - these notify the application that a GATT procedure has
+ * timed out while waiting for a response.
+ */
+typedef void ble_gattc_tmo_fn(struct ble_gattc_proc *proc);
+
+static ble_gattc_tmo_fn ble_gattc_mtu_tmo;
+static ble_gattc_tmo_fn ble_gattc_disc_all_svcs_tmo;
+static ble_gattc_tmo_fn ble_gattc_disc_svc_uuid_tmo;
+static ble_gattc_tmo_fn ble_gattc_find_inc_svcs_tmo;
+static ble_gattc_tmo_fn ble_gattc_disc_all_chrs_tmo;
+static ble_gattc_tmo_fn ble_gattc_disc_chr_uuid_tmo;
+static ble_gattc_tmo_fn ble_gattc_disc_all_dscs_tmo;
+static ble_gattc_tmo_fn ble_gattc_read_tmo;
+static ble_gattc_tmo_fn ble_gattc_read_uuid_tmo;
+static ble_gattc_tmo_fn ble_gattc_read_long_tmo;
+static ble_gattc_tmo_fn ble_gattc_read_mult_tmo;
+static ble_gattc_tmo_fn ble_gattc_write_tmo;
+static ble_gattc_tmo_fn ble_gattc_write_long_tmo;
+static ble_gattc_tmo_fn ble_gattc_write_reliable_tmo;
+static ble_gattc_tmo_fn ble_gattc_indicate_tmo;
+
+static ble_gattc_tmo_fn * const
+ble_gattc_tmo_dispatch[BLE_GATT_OP_CNT] = {
+    [BLE_GATT_OP_MTU]               = ble_gattc_mtu_tmo,
+    [BLE_GATT_OP_DISC_ALL_SVCS]     = ble_gattc_disc_all_svcs_tmo,
+    [BLE_GATT_OP_DISC_SVC_UUID]     = ble_gattc_disc_svc_uuid_tmo,
+    [BLE_GATT_OP_FIND_INC_SVCS]     = ble_gattc_find_inc_svcs_tmo,
+    [BLE_GATT_OP_DISC_ALL_CHRS]     = ble_gattc_disc_all_chrs_tmo,
+    [BLE_GATT_OP_DISC_CHR_UUID]     = ble_gattc_disc_chr_uuid_tmo,
+    [BLE_GATT_OP_DISC_ALL_DSCS]     = ble_gattc_disc_all_dscs_tmo,
+    [BLE_GATT_OP_READ]              = ble_gattc_read_tmo,
+    [BLE_GATT_OP_READ_UUID]         = ble_gattc_read_uuid_tmo,
+    [BLE_GATT_OP_READ_LONG]         = ble_gattc_read_long_tmo,
+    [BLE_GATT_OP_READ_MULT]         = ble_gattc_read_mult_tmo,
+    [BLE_GATT_OP_WRITE]             = ble_gattc_write_tmo,
+    [BLE_GATT_OP_WRITE_LONG]        = ble_gattc_write_long_tmo,
+    [BLE_GATT_OP_WRITE_RELIABLE]    = ble_gattc_write_reliable_tmo,
+    [BLE_GATT_OP_INDICATE]          = ble_gattc_indicate_tmo,
+};
+
+/**
  * Receive functions - these handle specific incoming responses and apply them
  * to the appropriate active GATT procedure.
  */
@@ -767,7 +812,7 @@ ble_gattc_process_resume_status(struct ble_gattc_proc *proc, int status)
 static ble_gattc_err_fn *
 ble_gattc_err_dispatch_get(uint8_t op)
 {
-    BLE_HS_DBG_ASSERT(op < BLE_GATT_OP_MAX);
+    BLE_HS_DBG_ASSERT(op < BLE_GATT_OP_CNT);
     return ble_gattc_err_dispatch[op];
 }
 
@@ -777,10 +822,17 @@ ble_gattc_err_dispatch_get(uint8_t op)
 static ble_gattc_resume_fn *
 ble_gattc_resume_dispatch_get(uint8_t op)
 {
-    BLE_HS_DBG_ASSERT(op < BLE_GATT_OP_MAX);
+    BLE_HS_DBG_ASSERT(op < BLE_GATT_OP_CNT);
     return ble_gattc_resume_dispatch[op];
 }
 
+static ble_gattc_tmo_fn *
+ble_gattc_tmo_dispatch_get(uint8_t op)
+{
+    BLE_HS_DBG_ASSERT(op < BLE_GATT_OP_CNT);
+    return ble_gattc_tmo_dispatch[op];
+}
+
 typedef int ble_gattc_match_fn(struct ble_gattc_proc *proc, void *arg);
 
 struct ble_gattc_criteria_conn_op {
@@ -1089,6 +1141,20 @@ ble_gattc_ticks_until_resume(void)
     return diff;
 }
 
+static void
+ble_gattc_proc_timeout(struct ble_gattc_proc *proc)
+{
+    ble_gattc_tmo_fn *cb;
+
+    BLE_HS_DBG_ASSERT(!ble_hs_locked_by_cur_task());
+    ble_gattc_dbg_assert_proc_not_inserted(proc);
+
+    cb = ble_gattc_tmo_dispatch_get(proc->op);
+    if (cb != NULL) {
+        cb(proc);
+    }
+}
+
 /**
  * Times out expired GATT client procedures.
  *
@@ -1112,6 +1178,9 @@ ble_gattc_timer(void)
     /* Terminate the connection associated with each timed-out procedure. */
     while ((proc = STAILQ_FIRST(&exp_list)) != NULL) {
         STATS_INC(ble_gattc_stats, proc_timeout);
+
+        ble_gattc_proc_timeout(proc);
+
         ble_gap_terminate(proc->conn_handle, BLE_ERR_REM_USER_CONN_TERM);
 
         STAILQ_REMOVE_HEAD(&exp_list, next);
@@ -1185,6 +1254,15 @@ ble_gattc_mtu_cb(struct ble_gattc_proc *proc, int status, uint16_t
att_handle,
     return rc;
 }
 
+static void
+ble_gattc_mtu_tmo(struct ble_gattc_proc *proc)
+{
+    BLE_HS_DBG_ASSERT(!ble_hs_locked_by_cur_task());
+    ble_gattc_dbg_assert_proc_not_inserted(proc);
+
+    ble_gattc_mtu_cb(proc, BLE_HS_ETIMEOUT, 0, 0);
+}
+
 /**
  * Handles an incoming ATT error response for the specified mtu-exchange proc.
  */
@@ -1300,6 +1378,15 @@ ble_gattc_disc_all_svcs_cb(struct ble_gattc_proc *proc,
     return rc;
 }
 
+static void
+ble_gattc_disc_all_svcs_tmo(struct ble_gattc_proc *proc)
+{
+    BLE_HS_DBG_ASSERT(!ble_hs_locked_by_cur_task());
+    ble_gattc_dbg_assert_proc_not_inserted(proc);
+
+    ble_gattc_disc_all_svcs_cb(proc, BLE_HS_ETIMEOUT, 0, 0);
+}
+
 /**
  * Triggers a pending transmit for the specified discover-all-services proc.
  */
@@ -1533,6 +1620,15 @@ ble_gattc_disc_svc_uuid_cb(struct ble_gattc_proc *proc, int status,
     return rc;
 }
 
+static void
+ble_gattc_disc_svc_uuid_tmo(struct ble_gattc_proc *proc)
+{
+    BLE_HS_DBG_ASSERT(!ble_hs_locked_by_cur_task());
+    ble_gattc_dbg_assert_proc_not_inserted(proc);
+
+    ble_gattc_disc_svc_uuid_cb(proc, BLE_HS_ETIMEOUT, 0, 0);
+}
+
 /**
  * Triggers a pending transmit for the specified discover-service-by-uuid proc.
  */
@@ -1751,6 +1847,15 @@ ble_gattc_find_inc_svcs_cb(struct ble_gattc_proc *proc, int status,
     return rc;
 }
 
+static void
+ble_gattc_find_inc_svcs_tmo(struct ble_gattc_proc *proc)
+{
+    BLE_HS_DBG_ASSERT(!ble_hs_locked_by_cur_task());
+    ble_gattc_dbg_assert_proc_not_inserted(proc);
+
+    ble_gattc_find_inc_svcs_cb(proc, BLE_HS_ETIMEOUT, 0, 0);
+}
+
 /**
  * Triggers a pending transmit for the specified find-included-services proc.
  */
@@ -2086,6 +2191,15 @@ ble_gattc_disc_all_chrs_cb(struct ble_gattc_proc *proc, int status,
     return rc;
 }
 
+static void
+ble_gattc_disc_all_chrs_tmo(struct ble_gattc_proc *proc)
+{
+    BLE_HS_DBG_ASSERT(!ble_hs_locked_by_cur_task());
+    ble_gattc_dbg_assert_proc_not_inserted(proc);
+
+    ble_gattc_disc_all_chrs_cb(proc, BLE_HS_ETIMEOUT, 0, NULL);
+}
+
 /**
  * Triggers a pending transmit for the specified discover-all-characteristics
  * proc.
@@ -2330,6 +2444,15 @@ ble_gattc_disc_chr_uuid_cb(struct ble_gattc_proc *proc, int status,
     return rc;
 }
 
+static void
+ble_gattc_disc_chr_uuid_tmo(struct ble_gattc_proc *proc)
+{
+    BLE_HS_DBG_ASSERT(!ble_hs_locked_by_cur_task());
+    ble_gattc_dbg_assert_proc_not_inserted(proc);
+
+    ble_gattc_disc_chr_uuid_cb(proc, BLE_HS_ETIMEOUT, 0, NULL);
+}
+
 /**
  * Triggers a pending transmit for the specified
  * discover-characteristic-by-uuid proc.
@@ -2589,6 +2712,15 @@ ble_gattc_disc_all_dscs_cb(struct ble_gattc_proc *proc, int status,
     return rc;
 }
 
+static void
+ble_gattc_disc_all_dscs_tmo(struct ble_gattc_proc *proc)
+{
+    BLE_HS_DBG_ASSERT(!ble_hs_locked_by_cur_task());
+    ble_gattc_dbg_assert_proc_not_inserted(proc);
+
+    ble_gattc_disc_all_dscs_cb(proc, BLE_HS_ETIMEOUT, 0, NULL);
+}
+
 /**
  * Triggers a pending transmit for the specified discover-all-descriptors proc.
  */
@@ -2807,6 +2939,15 @@ ble_gattc_read_cb(struct ble_gattc_proc *proc, int status,
     return rc;
 }
 
+static void
+ble_gattc_read_tmo(struct ble_gattc_proc *proc)
+{
+    BLE_HS_DBG_ASSERT(!ble_hs_locked_by_cur_task());
+    ble_gattc_dbg_assert_proc_not_inserted(proc);
+
+    ble_gattc_read_cb(proc, BLE_HS_ETIMEOUT, 0, NULL);
+}
+
 /**
  * Handles an incoming ATT error response for the specified
  * read-characteristic-value proc.
@@ -2948,6 +3089,15 @@ ble_gattc_read_uuid_cb(struct ble_gattc_proc *proc, int status,
     return rc;
 }
 
+static void
+ble_gattc_read_uuid_tmo(struct ble_gattc_proc *proc)
+{
+    BLE_HS_DBG_ASSERT(!ble_hs_locked_by_cur_task());
+    ble_gattc_dbg_assert_proc_not_inserted(proc);
+
+    ble_gattc_read_uuid_cb(proc, BLE_HS_ETIMEOUT, 0, NULL);
+}
+
 /**
  * Handles an incoming ATT error response for the specified
  * read-using-characteristic-uuid proc.
@@ -3132,6 +3282,15 @@ ble_gattc_read_long_cb(struct ble_gattc_proc *proc, int status,
     return rc;
 }
 
+static void
+ble_gattc_read_long_tmo(struct ble_gattc_proc *proc)
+{
+    BLE_HS_DBG_ASSERT(!ble_hs_locked_by_cur_task());
+    ble_gattc_dbg_assert_proc_not_inserted(proc);
+
+    ble_gattc_read_long_cb(proc, BLE_HS_ETIMEOUT, 0, NULL);
+}
+
 /**
  * Triggers a pending transmit for the specified read-long-characteristic proc.
  */
@@ -3349,6 +3508,15 @@ ble_gattc_read_mult_cb(struct ble_gattc_proc *proc, int status,
     return rc;
 }
 
+static void
+ble_gattc_read_mult_tmo(struct ble_gattc_proc *proc)
+{
+    BLE_HS_DBG_ASSERT(!ble_hs_locked_by_cur_task());
+    ble_gattc_dbg_assert_proc_not_inserted(proc);
+
+    ble_gattc_read_mult_cb(proc, BLE_HS_ETIMEOUT, 0, 0);
+}
+
 /**
  * Handles an incoming ATT error response for the specified
  * read-multiple-characteristics proc.
@@ -3549,6 +3717,15 @@ ble_gattc_write_cb(struct ble_gattc_proc *proc, int status,
     return rc;
 }
 
+static void
+ble_gattc_write_tmo(struct ble_gattc_proc *proc)
+{
+    BLE_HS_DBG_ASSERT(!ble_hs_locked_by_cur_task());
+    ble_gattc_dbg_assert_proc_not_inserted(proc);
+
+    ble_gattc_write_cb(proc, BLE_HS_ETIMEOUT, 0);
+}
+
 /**
  * Handles an incoming ATT error response for the specified
  * write-characteristic-value proc.
@@ -3697,6 +3874,15 @@ ble_gattc_write_long_cb(struct ble_gattc_proc *proc, int status,
     return rc;
 }
 
+static void
+ble_gattc_write_long_tmo(struct ble_gattc_proc *proc)
+{
+    BLE_HS_DBG_ASSERT(!ble_hs_locked_by_cur_task());
+    ble_gattc_dbg_assert_proc_not_inserted(proc);
+
+    ble_gattc_write_long_cb(proc, BLE_HS_ETIMEOUT, 0);
+}
+
 /**
  * Triggers a pending transmit for the specified
  * write-long-characteristic-value proc.
@@ -4001,6 +4187,15 @@ ble_gattc_write_reliable_cb(struct ble_gattc_proc *proc, int status,
     return rc;
 }
 
+static void
+ble_gattc_write_reliable_tmo(struct ble_gattc_proc *proc)
+{
+    BLE_HS_DBG_ASSERT(!ble_hs_locked_by_cur_task());
+    ble_gattc_dbg_assert_proc_not_inserted(proc);
+
+    ble_gattc_write_reliable_cb(proc, BLE_HS_ETIMEOUT, 0);
+}
+
 /**
  * Triggers a pending transmit for the specified
  * write-reliable-characteristic-value proc.
@@ -4402,6 +4597,16 @@ ble_gattc_indicate_err(struct ble_gattc_proc *proc, int status,
     ble_gatts_send_next_indicate(proc->conn_handle);
 }
 
+static void
+ble_gattc_indicate_tmo(struct ble_gattc_proc *proc)
+{
+    BLE_HS_DBG_ASSERT(!ble_hs_locked_by_cur_task());
+    ble_gattc_dbg_assert_proc_not_inserted(proc);
+
+    ble_gap_notify_tx_event(BLE_HS_ETIMEOUT, proc->conn_handle,
+                            proc->indicate.chr_val_handle, 1);
+}
+
 /**
  * Handles an incoming handle-value-confirmation for the specified indication
  * proc.

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/ec16344c/net/nimble/host/test/src/ble_gatt_conn_test.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/test/src/ble_gatt_conn_test.c b/net/nimble/host/test/src/ble_gatt_conn_test.c
index 6a5cba6..3fd7cc3 100644
--- a/net/nimble/host/test/src/ble_gatt_conn_test.c
+++ b/net/nimble/host/test/src/ble_gatt_conn_test.c
@@ -29,8 +29,9 @@
 
 static uint8_t ble_gatt_conn_test_write_value[] = { 1, 3, 64, 21, 6 };
 
-struct ble_gatt_conn_test_cb_arg {
+struct ble_gatt_conn_test_arg {
     uint16_t exp_conn_handle;
+    int exp_status;
     int called;
 };
 
@@ -80,14 +81,14 @@ ble_gatt_conn_test_mtu_cb(uint16_t conn_handle,
                           const struct ble_gatt_error *error,
                           uint16_t mtu, void *arg)
 {
-    struct ble_gatt_conn_test_cb_arg *cb_arg;
+    struct ble_gatt_conn_test_arg *cb_arg;
 
     cb_arg = arg;
 
     TEST_ASSERT(cb_arg->exp_conn_handle == conn_handle);
     TEST_ASSERT(!cb_arg->called);
     TEST_ASSERT_FATAL(error != NULL);
-    TEST_ASSERT(error->status == BLE_HS_ENOTCONN);
+    TEST_ASSERT(error->status == cb_arg->exp_status);
     TEST_ASSERT(mtu == 0);
 
     cb_arg->called++;
@@ -101,14 +102,14 @@ ble_gatt_conn_test_disc_all_svcs_cb(uint16_t conn_handle,
                                     const struct ble_gatt_svc *service,
                                     void *arg)
 {
-    struct ble_gatt_conn_test_cb_arg *cb_arg;
+    struct ble_gatt_conn_test_arg *cb_arg;
 
     cb_arg = arg;
 
     TEST_ASSERT(cb_arg->exp_conn_handle == conn_handle);
     TEST_ASSERT(!cb_arg->called);
     TEST_ASSERT_FATAL(error != NULL);
-    TEST_ASSERT(error->status == BLE_HS_ENOTCONN);
+    TEST_ASSERT(error->status == cb_arg->exp_status);
     TEST_ASSERT(service == NULL);
 
     cb_arg->called++;
@@ -122,14 +123,14 @@ ble_gatt_conn_test_disc_svc_uuid_cb(uint16_t conn_handle,
                                     const struct ble_gatt_svc *service,
                                     void *arg)
 {
-    struct ble_gatt_conn_test_cb_arg *cb_arg;
+    struct ble_gatt_conn_test_arg *cb_arg;
 
     cb_arg = arg;
 
     TEST_ASSERT(cb_arg->exp_conn_handle == conn_handle);
     TEST_ASSERT(!cb_arg->called);
     TEST_ASSERT_FATAL(error != NULL);
-    TEST_ASSERT(error->status == BLE_HS_ENOTCONN);
+    TEST_ASSERT(error->status == cb_arg->exp_status);
     TEST_ASSERT(service == NULL);
 
     cb_arg->called++;
@@ -143,14 +144,14 @@ ble_gatt_conn_test_find_inc_svcs_cb(uint16_t conn_handle,
                                     const struct ble_gatt_svc *service,
                                     void *arg)
 {
-    struct ble_gatt_conn_test_cb_arg *cb_arg;
+    struct ble_gatt_conn_test_arg *cb_arg;
 
     cb_arg = arg;
 
     TEST_ASSERT(cb_arg->exp_conn_handle == conn_handle);
     TEST_ASSERT(!cb_arg->called);
     TEST_ASSERT_FATAL(error != NULL);
-    TEST_ASSERT(error->status == BLE_HS_ENOTCONN);
+    TEST_ASSERT(error->status == cb_arg->exp_status);
     TEST_ASSERT(service == NULL);
 
     cb_arg->called++;
@@ -163,14 +164,14 @@ ble_gatt_conn_test_disc_all_chrs_cb(uint16_t conn_handle,
                                     const struct ble_gatt_error *error,
                                     const struct ble_gatt_chr *chr, void *arg)
 {
-    struct ble_gatt_conn_test_cb_arg *cb_arg;
+    struct ble_gatt_conn_test_arg *cb_arg;
 
     cb_arg = arg;
 
     TEST_ASSERT(cb_arg->exp_conn_handle == conn_handle);
     TEST_ASSERT(!cb_arg->called);
     TEST_ASSERT_FATAL(error != NULL);
-    TEST_ASSERT(error->status == BLE_HS_ENOTCONN);
+    TEST_ASSERT(error->status == cb_arg->exp_status);
     TEST_ASSERT(chr == NULL);
 
     cb_arg->called++;
@@ -183,14 +184,14 @@ ble_gatt_conn_test_disc_chr_uuid_cb(uint16_t conn_handle,
                                     const struct ble_gatt_error *error,
                                     const struct ble_gatt_chr *chr, void *arg)
 {
-    struct ble_gatt_conn_test_cb_arg *cb_arg;
+    struct ble_gatt_conn_test_arg *cb_arg;
 
     cb_arg = arg;
 
     TEST_ASSERT(cb_arg->exp_conn_handle == conn_handle);
     TEST_ASSERT(!cb_arg->called);
     TEST_ASSERT_FATAL(error != NULL);
-    TEST_ASSERT(error->status == BLE_HS_ENOTCONN);
+    TEST_ASSERT(error->status == cb_arg->exp_status);
     TEST_ASSERT(chr == NULL);
 
     cb_arg->called++;
@@ -205,14 +206,14 @@ ble_gatt_conn_test_disc_all_dscs_cb(uint16_t conn_handle,
                                     const struct ble_gatt_dsc *dsc,
                                     void *arg)
 {
-    struct ble_gatt_conn_test_cb_arg *cb_arg;
+    struct ble_gatt_conn_test_arg *cb_arg;
 
     cb_arg = arg;
 
     TEST_ASSERT(cb_arg->exp_conn_handle == conn_handle);
     TEST_ASSERT(!cb_arg->called);
     TEST_ASSERT_FATAL(error != NULL);
-    TEST_ASSERT(error->status == BLE_HS_ENOTCONN);
+    TEST_ASSERT(error->status == cb_arg->exp_status);
     TEST_ASSERT(dsc == NULL);
 
     cb_arg->called++;
@@ -225,14 +226,14 @@ ble_gatt_conn_test_read_cb(uint16_t conn_handle,
                            const struct ble_gatt_error *error,
                            struct ble_gatt_attr *attr, void *arg)
 {
-    struct ble_gatt_conn_test_cb_arg *cb_arg;
+    struct ble_gatt_conn_test_arg *cb_arg;
 
     cb_arg = arg;
 
     TEST_ASSERT(cb_arg->exp_conn_handle == conn_handle);
     TEST_ASSERT(!cb_arg->called);
     TEST_ASSERT_FATAL(error != NULL);
-    TEST_ASSERT(error->status == BLE_HS_ENOTCONN);
+    TEST_ASSERT(error->status == cb_arg->exp_status);
     TEST_ASSERT(attr == NULL);
 
     cb_arg->called++;
@@ -245,14 +246,14 @@ ble_gatt_conn_test_read_uuid_cb(uint16_t conn_handle,
                                 const struct ble_gatt_error *error,
                                 struct ble_gatt_attr *attr, void *arg)
 {
-    struct ble_gatt_conn_test_cb_arg *cb_arg;
+    struct ble_gatt_conn_test_arg *cb_arg;
 
     cb_arg = arg;
 
     TEST_ASSERT(cb_arg->exp_conn_handle == conn_handle);
     TEST_ASSERT(!cb_arg->called);
     TEST_ASSERT_FATAL(error != NULL);
-    TEST_ASSERT(error->status == BLE_HS_ENOTCONN);
+    TEST_ASSERT(error->status == cb_arg->exp_status);
     TEST_ASSERT(attr == NULL);
 
     cb_arg->called++;
@@ -265,14 +266,14 @@ ble_gatt_conn_test_read_long_cb(uint16_t conn_handle,
                                 const struct ble_gatt_error *error,
                                 struct ble_gatt_attr *attr, void *arg)
 {
-    struct ble_gatt_conn_test_cb_arg *cb_arg;
+    struct ble_gatt_conn_test_arg *cb_arg;
 
     cb_arg = arg;
 
     TEST_ASSERT(cb_arg->exp_conn_handle == conn_handle);
     TEST_ASSERT(!cb_arg->called);
     TEST_ASSERT_FATAL(error != NULL);
-    TEST_ASSERT(error->status == BLE_HS_ENOTCONN);
+    TEST_ASSERT(error->status == cb_arg->exp_status);
     TEST_ASSERT(attr == NULL);
 
     cb_arg->called++;
@@ -284,14 +285,14 @@ ble_gatt_conn_test_read_mult_cb(uint16_t conn_handle,
                                 const struct ble_gatt_error *error,
                                 struct ble_gatt_attr *attr, void *arg)
 {
-    struct ble_gatt_conn_test_cb_arg *cb_arg;
+    struct ble_gatt_conn_test_arg *cb_arg;
 
     cb_arg = arg;
 
     TEST_ASSERT(cb_arg->exp_conn_handle == conn_handle);
     TEST_ASSERT(!cb_arg->called);
     TEST_ASSERT_FATAL(error != NULL);
-    TEST_ASSERT(error->status == BLE_HS_ENOTCONN);
+    TEST_ASSERT(error->status == cb_arg->exp_status);
     TEST_ASSERT(attr->om == NULL);
 
     cb_arg->called++;
@@ -305,14 +306,14 @@ ble_gatt_conn_test_write_cb(uint16_t conn_handle,
                             struct ble_gatt_attr *attr,
                             void *arg)
 {
-    struct ble_gatt_conn_test_cb_arg *cb_arg;
+    struct ble_gatt_conn_test_arg *cb_arg;
 
     cb_arg = arg;
 
     TEST_ASSERT(cb_arg->exp_conn_handle == conn_handle);
     TEST_ASSERT(!cb_arg->called);
     TEST_ASSERT_FATAL(error != NULL);
-    TEST_ASSERT(error->status == BLE_HS_ENOTCONN);
+    TEST_ASSERT(error->status == cb_arg->exp_status);
     TEST_ASSERT(attr != NULL);
     TEST_ASSERT(attr->handle == BLE_GATT_BREAK_TEST_WRITE_ATTR_HANDLE);
 
@@ -326,14 +327,14 @@ ble_gatt_conn_test_write_long_cb(uint16_t conn_handle,
                                  const struct ble_gatt_error *error,
                                  struct ble_gatt_attr *attr, void *arg)
 {
-    struct ble_gatt_conn_test_cb_arg *cb_arg;
+    struct ble_gatt_conn_test_arg *cb_arg;
 
     cb_arg = arg;
 
     TEST_ASSERT(cb_arg->exp_conn_handle == conn_handle);
     TEST_ASSERT(!cb_arg->called);
     TEST_ASSERT_FATAL(error != NULL);
-    TEST_ASSERT(error->status == BLE_HS_ENOTCONN);
+    TEST_ASSERT(error->status == cb_arg->exp_status);
     TEST_ASSERT(attr != NULL);
     TEST_ASSERT(attr->handle == BLE_GATT_BREAK_TEST_WRITE_ATTR_HANDLE);
 
@@ -349,14 +350,14 @@ ble_gatt_conn_test_write_rel_cb(uint16_t conn_handle,
                                 uint8_t num_attrs,
                                 void *arg)
 {
-    struct ble_gatt_conn_test_cb_arg *cb_arg;
+    struct ble_gatt_conn_test_arg *cb_arg;
 
     cb_arg = arg;
 
     TEST_ASSERT(cb_arg->exp_conn_handle == conn_handle);
     TEST_ASSERT(!cb_arg->called);
     TEST_ASSERT_FATAL(error != NULL);
-    TEST_ASSERT(error->status == BLE_HS_ENOTCONN);
+    TEST_ASSERT(error->status == cb_arg->exp_status);
     TEST_ASSERT(attrs != NULL);
 
     cb_arg->called++;
@@ -366,20 +367,20 @@ ble_gatt_conn_test_write_rel_cb(uint16_t conn_handle,
 
 TEST_CASE(ble_gatt_conn_test_disconnect)
 {
-    struct ble_gatt_conn_test_cb_arg mtu_arg            = { 0 };
-    struct ble_gatt_conn_test_cb_arg disc_all_svcs_arg  = { 0 };
-    struct ble_gatt_conn_test_cb_arg disc_svc_uuid_arg  = { 0 };
-    struct ble_gatt_conn_test_cb_arg find_inc_svcs_arg  = { 0 };
-    struct ble_gatt_conn_test_cb_arg disc_all_chrs_arg  = { 0 };
-    struct ble_gatt_conn_test_cb_arg disc_chr_uuid_arg  = { 0 };
-    struct ble_gatt_conn_test_cb_arg disc_all_dscs_arg  = { 0 };
-    struct ble_gatt_conn_test_cb_arg read_arg           = { 0 };
-    struct ble_gatt_conn_test_cb_arg read_uuid_arg      = { 0 };
-    struct ble_gatt_conn_test_cb_arg read_long_arg      = { 0 };
-    struct ble_gatt_conn_test_cb_arg read_mult_arg      = { 0 };
-    struct ble_gatt_conn_test_cb_arg write_arg          = { 0 };
-    struct ble_gatt_conn_test_cb_arg write_long_arg     = { 0 };
-    struct ble_gatt_conn_test_cb_arg write_rel_arg      = { 0 };
+    struct ble_gatt_conn_test_arg mtu_arg            = { 0, BLE_HS_ENOTCONN };
+    struct ble_gatt_conn_test_arg disc_all_svcs_arg  = { 0, BLE_HS_ENOTCONN };
+    struct ble_gatt_conn_test_arg disc_svc_uuid_arg  = { 0, BLE_HS_ENOTCONN };
+    struct ble_gatt_conn_test_arg find_inc_svcs_arg  = { 0, BLE_HS_ENOTCONN };
+    struct ble_gatt_conn_test_arg disc_all_chrs_arg  = { 0, BLE_HS_ENOTCONN };
+    struct ble_gatt_conn_test_arg disc_chr_uuid_arg  = { 0, BLE_HS_ENOTCONN };
+    struct ble_gatt_conn_test_arg disc_all_dscs_arg  = { 0, BLE_HS_ENOTCONN };
+    struct ble_gatt_conn_test_arg read_arg           = { 0, BLE_HS_ENOTCONN };
+    struct ble_gatt_conn_test_arg read_uuid_arg      = { 0, BLE_HS_ENOTCONN };
+    struct ble_gatt_conn_test_arg read_long_arg      = { 0, BLE_HS_ENOTCONN };
+    struct ble_gatt_conn_test_arg read_mult_arg      = { 0, BLE_HS_ENOTCONN };
+    struct ble_gatt_conn_test_arg write_arg          = { 0, BLE_HS_ENOTCONN };
+    struct ble_gatt_conn_test_arg write_long_arg     = { 0, BLE_HS_ENOTCONN };
+    struct ble_gatt_conn_test_arg write_rel_arg      = { 0, BLE_HS_ENOTCONN };
     struct ble_gatt_attr attr;
     uint16_t attr_handle;
     int rc;
@@ -552,7 +553,8 @@ TEST_CASE(ble_gatt_conn_test_disconnect)
 }
 
 static void
-ble_gatt_conn_test_util_timeout(uint16_t conn_handle)
+ble_gatt_conn_test_util_timeout(uint16_t conn_handle,
+                                struct ble_gatt_conn_test_arg *arg)
 {
     int32_t ticks_from_now;
 
@@ -573,11 +575,32 @@ ble_gatt_conn_test_util_timeout(uint16_t conn_handle)
                                           BLE_ERR_REM_USER_CONN_TERM);
     ble_hs_test_util_rx_disconn_complete(conn_handle,
                                          BLE_ERR_REM_USER_CONN_TERM);
+
+    /* Ensure GATT callback was called with timeout status. */
+    if (arg != NULL) {
+        TEST_ASSERT(arg->called == 1);
+    }
 }
 
 TEST_CASE(ble_gatt_conn_test_timeout)
 {
     static const uint8_t peer_addr[6] = { 1, 2, 3, 4, 5, 6 };
+
+    struct ble_gatt_conn_test_arg mtu_arg            = { 1, BLE_HS_ETIMEOUT };
+    struct ble_gatt_conn_test_arg disc_all_svcs_arg  = { 1, BLE_HS_ETIMEOUT };
+    struct ble_gatt_conn_test_arg disc_svc_uuid_arg  = { 1, BLE_HS_ETIMEOUT };
+    struct ble_gatt_conn_test_arg find_inc_svcs_arg  = { 1, BLE_HS_ETIMEOUT };
+    struct ble_gatt_conn_test_arg disc_all_chrs_arg  = { 1, BLE_HS_ETIMEOUT };
+    struct ble_gatt_conn_test_arg disc_chr_uuid_arg  = { 1, BLE_HS_ETIMEOUT };
+    struct ble_gatt_conn_test_arg disc_all_dscs_arg  = { 1, BLE_HS_ETIMEOUT };
+    struct ble_gatt_conn_test_arg read_arg           = { 1, BLE_HS_ETIMEOUT };
+    struct ble_gatt_conn_test_arg read_uuid_arg      = { 1, BLE_HS_ETIMEOUT };
+    struct ble_gatt_conn_test_arg read_long_arg      = { 1, BLE_HS_ETIMEOUT };
+    struct ble_gatt_conn_test_arg read_mult_arg      = { 1, BLE_HS_ETIMEOUT };
+    struct ble_gatt_conn_test_arg write_arg          = { 1, BLE_HS_ETIMEOUT };
+    struct ble_gatt_conn_test_arg write_long_arg     = { 1, BLE_HS_ETIMEOUT };
+    struct ble_gatt_conn_test_arg write_rel_arg      = { 1, BLE_HS_ETIMEOUT };
+
     struct ble_gatt_attr attr;
     int32_t ticks_from_now;
     uint16_t attr_handle;
@@ -596,97 +619,105 @@ TEST_CASE(ble_gatt_conn_test_timeout)
 
     /*** MTU. */
     ble_hs_test_util_create_conn(1, peer_addr, NULL, NULL);
-    rc = ble_gattc_exchange_mtu(1, ble_gatt_conn_test_mtu_cb, NULL);
+    rc = ble_gattc_exchange_mtu(1, ble_gatt_conn_test_mtu_cb, &mtu_arg);
     TEST_ASSERT_FATAL(rc == 0);
-    ble_gatt_conn_test_util_timeout(1);
+    ble_gatt_conn_test_util_timeout(1, &mtu_arg);
 
     /*** Discover all services. */
     ble_hs_test_util_create_conn(1, peer_addr, NULL, NULL);
-    rc = ble_gattc_disc_all_svcs(1, ble_gatt_conn_test_disc_all_svcs_cb, NULL);
+    rc = ble_gattc_disc_all_svcs(1, ble_gatt_conn_test_disc_all_svcs_cb,
+                                 &disc_all_svcs_arg);
     TEST_ASSERT_FATAL(rc == 0);
-    ble_gatt_conn_test_util_timeout(1);
+    ble_gatt_conn_test_util_timeout(1, &disc_all_svcs_arg);
 
     /*** Discover services by UUID. */
     ble_hs_test_util_create_conn(1, peer_addr, NULL, NULL);
     rc = ble_gattc_disc_svc_by_uuid(1, BLE_UUID16(0x1111),
-                                    ble_gatt_conn_test_disc_svc_uuid_cb, NULL);
+                                    ble_gatt_conn_test_disc_svc_uuid_cb,
+                                    &disc_svc_uuid_arg);
     TEST_ASSERT_FATAL(rc == 0);
-    ble_gatt_conn_test_util_timeout(1);
+    ble_gatt_conn_test_util_timeout(1, &disc_svc_uuid_arg);
 
     /*** Find included services. */
     ble_hs_test_util_create_conn(1, peer_addr, NULL, NULL);
     rc = ble_gattc_find_inc_svcs(1, 1, 0xffff,
-                                 ble_gatt_conn_test_find_inc_svcs_cb, NULL);
+                                 ble_gatt_conn_test_find_inc_svcs_cb,
+                                 &find_inc_svcs_arg);
     TEST_ASSERT_FATAL(rc == 0);
-    ble_gatt_conn_test_util_timeout(1);
+    ble_gatt_conn_test_util_timeout(1, &find_inc_svcs_arg);
 
     /*** Discover all characteristics. */
     ble_hs_test_util_create_conn(1, peer_addr, NULL, NULL);
     rc = ble_gattc_disc_all_chrs(1, 1, 0xffff,
-                                 ble_gatt_conn_test_disc_all_chrs_cb, NULL);
+                                 ble_gatt_conn_test_disc_all_chrs_cb,
+                                 &disc_all_chrs_arg);
     TEST_ASSERT_FATAL(rc == 0);
-    ble_gatt_conn_test_util_timeout(1);
+    ble_gatt_conn_test_util_timeout(1, &disc_all_chrs_arg);
 
     /*** Discover all descriptors. */
     ble_hs_test_util_create_conn(1, peer_addr, NULL, NULL);
     rc = ble_gattc_disc_all_dscs(1, 3, 0xffff,
-                                 ble_gatt_conn_test_disc_all_dscs_cb, NULL);
+                                 ble_gatt_conn_test_disc_all_dscs_cb,
+                                 &disc_chr_uuid_arg);
     TEST_ASSERT_FATAL(rc == 0);
-    ble_gatt_conn_test_util_timeout(1);
+    ble_gatt_conn_test_util_timeout(1, &disc_chr_uuid_arg);
 
     /*** Discover characteristics by UUID. */
     ble_hs_test_util_create_conn(1, peer_addr, NULL, NULL);
     rc = ble_gattc_disc_chrs_by_uuid(1, 2, 0xffff, BLE_UUID16(0x2222),
                                      ble_gatt_conn_test_disc_chr_uuid_cb,
-                                     NULL);
+                                     &disc_all_dscs_arg);
     TEST_ASSERT_FATAL(rc == 0);
-    ble_gatt_conn_test_util_timeout(1);
+    ble_gatt_conn_test_util_timeout(1, &disc_all_dscs_arg);
 
     /*** Read. */
     ble_hs_test_util_create_conn(1, peer_addr, NULL, NULL);
     rc = ble_gattc_read(1, BLE_GATT_BREAK_TEST_READ_ATTR_HANDLE,
-                        ble_gatt_conn_test_read_cb, NULL);
+                        ble_gatt_conn_test_read_cb, &read_arg);
     TEST_ASSERT_FATAL(rc == 0);
-    ble_gatt_conn_test_util_timeout(1);
+    ble_gatt_conn_test_util_timeout(1, &read_arg);
 
     /*** Read by UUID. */
     ble_hs_test_util_create_conn(1, peer_addr, NULL, NULL);
     rc = ble_gattc_read_by_uuid(1, 1, 0xffff, BLE_UUID16(0x3333),
-                                ble_gatt_conn_test_read_uuid_cb, NULL);
+                                ble_gatt_conn_test_read_uuid_cb,
+                                &read_uuid_arg);
     TEST_ASSERT_FATAL(rc == 0);
-    ble_gatt_conn_test_util_timeout(1);
+    ble_gatt_conn_test_util_timeout(1, &read_uuid_arg);
 
     /*** Read long. */
     ble_hs_test_util_create_conn(1, peer_addr, NULL, NULL);
     rc = ble_gattc_read_long(1, BLE_GATT_BREAK_TEST_READ_ATTR_HANDLE,
-                             ble_gatt_conn_test_read_long_cb, NULL);
+                             ble_gatt_conn_test_read_long_cb,
+                             &read_long_arg);
     TEST_ASSERT_FATAL(rc == 0);
-    ble_gatt_conn_test_util_timeout(1);
+    ble_gatt_conn_test_util_timeout(1, &read_long_arg);
 
     /*** Read multiple. */
     ble_hs_test_util_create_conn(1, peer_addr, NULL, NULL);
     rc = ble_gattc_read_mult(1, ((uint16_t[3]){5,6,7}), 3,
-                             ble_gatt_conn_test_read_mult_cb, NULL);
+                             ble_gatt_conn_test_read_mult_cb,
+                             &read_mult_arg);
     TEST_ASSERT_FATAL(rc == 0);
-    ble_gatt_conn_test_util_timeout(1);
+    ble_gatt_conn_test_util_timeout(1, &read_mult_arg);
 
     /*** Write. */
     ble_hs_test_util_create_conn(1, peer_addr, NULL, NULL);
     rc = ble_hs_test_util_gatt_write_flat(
         1, BLE_GATT_BREAK_TEST_WRITE_ATTR_HANDLE,
         ble_gatt_conn_test_write_value, sizeof ble_gatt_conn_test_write_value,
-        ble_gatt_conn_test_write_cb, NULL);
+        ble_gatt_conn_test_write_cb, &write_arg);
     TEST_ASSERT_FATAL(rc == 0);
-    ble_gatt_conn_test_util_timeout(1);
+    ble_gatt_conn_test_util_timeout(1, &write_arg);
 
     /*** Write long. */
     ble_hs_test_util_create_conn(1, peer_addr, NULL, NULL);
     rc = ble_hs_test_util_gatt_write_long_flat(
         1, BLE_GATT_BREAK_TEST_WRITE_ATTR_HANDLE,
         ble_gatt_conn_test_write_value, sizeof ble_gatt_conn_test_write_value,
-        ble_gatt_conn_test_write_long_cb, NULL);
+        ble_gatt_conn_test_write_long_cb, &write_long_arg);
     TEST_ASSERT_FATAL(rc == 0);
-    ble_gatt_conn_test_util_timeout(1);
+    ble_gatt_conn_test_util_timeout(1, &write_long_arg);
 
     /*** Write reliable. */
     ble_hs_test_util_create_conn(1, peer_addr, NULL, NULL);
@@ -694,15 +725,15 @@ TEST_CASE(ble_gatt_conn_test_timeout)
     attr.offset = 0;
     attr.om = os_msys_get_pkthdr(0, 0);
     rc = ble_gattc_write_reliable(
-        1, &attr, 1, ble_gatt_conn_test_write_rel_cb, NULL);
+        1, &attr, 1, ble_gatt_conn_test_write_rel_cb, &write_rel_arg);
     TEST_ASSERT_FATAL(rc == 0);
-    ble_gatt_conn_test_util_timeout(1);
+    ble_gatt_conn_test_util_timeout(1, &write_rel_arg);
 
     /*** Indication. */
     ble_hs_test_util_create_conn(1, peer_addr, NULL, NULL);
     rc = ble_gattc_indicate(1, attr_handle);
     TEST_ASSERT_FATAL(rc == 0);
-    ble_gatt_conn_test_util_timeout(1);
+    ble_gatt_conn_test_util_timeout(1, NULL);
 }
 
 TEST_SUITE(ble_gatt_conn_suite)

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/ec16344c/net/nimble/host/test/src/ble_gatt_disc_s_test.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/test/src/ble_gatt_disc_s_test.c b/net/nimble/host/test/src/ble_gatt_disc_s_test.c
index b3f33ca..cb3d575 100644
--- a/net/nimble/host/test/src/ble_gatt_disc_s_test.c
+++ b/net/nimble/host/test/src/ble_gatt_disc_s_test.c
@@ -262,6 +262,10 @@ ble_gatt_disc_s_test_misc_disc_cb(uint16_t conn_handle,
         ble_gatt_disc_s_test_rx_complete = 1;
         break;
 
+    case BLE_HS_ETIMEOUT:
+        ble_gatt_disc_s_test_rx_complete = 1;
+        break;
+
     default:
         TEST_ASSERT(0);
     }


Mime
View raw message