You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by GitBox <gi...@apache.org> on 2018/12/21 17:55:31 UTC

[GitHub] rymanluk closed pull request #272: nimble/gap: Improve connection parameter update

rymanluk closed pull request #272: nimble/gap: Improve connection parameter update
URL: https://github.com/apache/mynewt-nimble/pull/272
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/nimble/host/src/ble_gap.c b/nimble/host/src/ble_gap.c
index 50e15969..153c5a85 100644
--- a/nimble/host/src/ble_gap.c
+++ b/nimble/host/src/ble_gap.c
@@ -85,7 +85,7 @@
  */
 #define BLE_GAP_CANCEL_RETRY_TIMEOUT_MS         100 /* ms */
 
-#define BLE_GAP_UPDATE_TIMEOUT_MS               30000 /* ms */
+#define BLE_GAP_UPDATE_TIMEOUT_MS               40000 /* ms */
 
 static const struct ble_gap_conn_params ble_gap_conn_params_dflt = {
     .scan_itvl = 0x0010,
@@ -1128,6 +1128,8 @@ ble_gap_rx_update_complete(struct hci_le_conn_upd_complete *evt)
             entry = ble_gap_update_entry_find(evt->connection_handle, NULL);
             if (entry != NULL && !(conn->bhc_flags & BLE_HS_CONN_F_MASTER)) {
                 ble_gap_update_to_l2cap(&entry->params, &l2cap_params);
+                entry->exp_os_ticks = ble_npl_time_get() +
+                                      ble_npl_time_ms_to_ticks32(BLE_GAP_UPDATE_TIMEOUT_MS);
             }
             break;
 
@@ -4014,15 +4016,17 @@ ble_gap_update_l2cap_cb(uint16_t conn_handle, int status, void *arg)
     /* Report failures and rejections.  Success gets reported when the
      * controller sends the connection update complete event.
      */
-    if (status != 0) {
-        ble_hs_lock();
-        entry = ble_gap_update_entry_remove(conn_handle);
-        ble_hs_unlock();
 
-        if (entry != NULL) {
-            ble_gap_update_entry_free(entry);
+    ble_hs_lock();
+    entry = ble_gap_update_entry_remove(conn_handle);
+    ble_hs_unlock();
+
+    if (entry != NULL) {
+        ble_gap_update_entry_free(entry);
+        if (status != 0) {
             ble_gap_update_notify(conn_handle, status);
         }
+        /* On success let's wait for the controller to notify about update */
     }
 }
 
diff --git a/nimble/host/test/src/ble_gap_test.c b/nimble/host/test/src/ble_gap_test.c
index baed307d..463c2787 100644
--- a/nimble/host/test/src/ble_gap_test.c
+++ b/nimble/host/test/src/ble_gap_test.c
@@ -1961,15 +1961,13 @@ ble_gap_test_util_update_l2cap(struct ble_gap_upd_params *params,
 
     /* Receive l2cap connection parameter update response. */
     ble_hs_test_util_rx_l2cap_update_rsp(2, id, l2cap_result);
-    if (l2cap_result == BLE_L2CAP_SIG_UPDATE_RSP_RESULT_ACCEPT) {
-        TEST_ASSERT(ble_gap_dbg_update_active(2));
+    TEST_ASSERT(!ble_gap_dbg_update_active(2));
 
+    if (l2cap_result == BLE_L2CAP_SIG_UPDATE_RSP_RESULT_ACCEPT) {
         /* Receive connection update complete event. */
         ble_gap_test_util_rx_update_complete(0, params);
     }
 
-    TEST_ASSERT(!ble_gap_dbg_update_active(2));
-
     TEST_ASSERT(ble_gap_test_event.type == BLE_GAP_EVENT_CONN_UPDATE);
     if (l2cap_result != BLE_L2CAP_SIG_UPDATE_RSP_RESULT_ACCEPT) {
         TEST_ASSERT(ble_gap_test_conn_status == BLE_HS_EREJECT);
@@ -2025,12 +2023,12 @@ ble_gap_test_util_update_no_l2cap_tmo(struct ble_gap_upd_params *params,
     /* Ensure no update event reported. */
     TEST_ASSERT(ble_gap_test_event.type == 0xff);
 
-    /* Advance 29 seconds; ensure no timeout reported. */
-    os_time_advance(29 * OS_TICKS_PER_SEC);
+    /* Advance 39 seconds; ensure no timeout reported. */
+    os_time_advance(39 * OS_TICKS_PER_SEC);
     ble_gap_timer();
     TEST_ASSERT(ble_gap_test_event.type == 0xff);
 
-    /* Advance 30th second; ensure timeout reported. */
+    /* Advance 40th second; ensure timeout reported. */
     os_time_advance(1 * OS_TICKS_PER_SEC);
 
     /* Timeout will result in a terminate HCI command being sent; schedule ack
@@ -2094,14 +2092,18 @@ ble_gap_test_util_update_l2cap_tmo(struct ble_gap_upd_params *params,
         /* Receive l2cap connection parameter update response. */
         ble_hs_test_util_rx_l2cap_update_rsp(
             2, id, BLE_L2CAP_SIG_UPDATE_RSP_RESULT_ACCEPT);
-    }
 
-    TEST_ASSERT(ble_gap_dbg_update_active(2));
+        TEST_ASSERT(!ble_gap_dbg_update_active(2));
+    } else {
+        TEST_ASSERT(ble_gap_dbg_update_active(2));
+    }
 
     /* Ensure no update event reported. */
     TEST_ASSERT(ble_gap_test_event.type == 0xff);
 
-    /* Advance 29 seconds; ensure no timeout reported. */
+    /* Advance 29 seconds; ensure no timeout reported.
+     * Note: L2CAP signaling timeout is 30 sec, GAP update timeout is 40 sec
+     */
     os_time_advance(29 * OS_TICKS_PER_SEC);
     ble_gap_timer();
     ble_l2cap_sig_timer();
@@ -2110,22 +2112,31 @@ ble_gap_test_util_update_l2cap_tmo(struct ble_gap_upd_params *params,
     /* Advance 30th second; ensure timeout reported. */
     os_time_advance(1 * OS_TICKS_PER_SEC);
 
-    /* Timeout will result in a terminate HCI command being sent; schedule ack
-     * from controller.
-     */
-    ble_hs_test_util_hci_ack_set_disconnect(0);
+    /* If L2CAP response has been received, GAP Timer is removed */
+     if (!rx_l2cap) {
 
-    ble_gap_timer();
-    ble_l2cap_sig_timer();
+         /* Timeout will result in a terminate HCI command being sent; schedule ack
+          * from controller.
+          */
+         ble_hs_test_util_hci_ack_set_disconnect(0);
 
-    /* Verify terminate was sent. */
-    ble_gap_test_util_verify_tx_disconnect();
+         ble_gap_timer();
+         ble_l2cap_sig_timer();
 
-    TEST_ASSERT(ble_gap_test_event.type == BLE_GAP_EVENT_CONN_UPDATE);
-    TEST_ASSERT(ble_gap_test_conn_status == BLE_HS_ETIMEOUT);
-    TEST_ASSERT(ble_gap_test_conn_desc.conn_handle == 2);
-    TEST_ASSERT(memcmp(ble_gap_test_conn_desc.peer_id_addr.val,
-                       peer_addr, 6) == 0);
+         /* Verify terminate was sent. */
+         ble_gap_test_util_verify_tx_disconnect();
+
+        TEST_ASSERT(ble_gap_test_event.type == BLE_GAP_EVENT_CONN_UPDATE);
+        TEST_ASSERT(ble_gap_test_conn_status == BLE_HS_ETIMEOUT);
+        TEST_ASSERT(ble_gap_test_conn_desc.conn_handle == 2);
+        TEST_ASSERT(memcmp(ble_gap_test_conn_desc.peer_id_addr.val,
+                           peer_addr, 6) == 0);
+    } else {
+        ble_gap_timer();
+        ble_l2cap_sig_timer();
+
+        TEST_ASSERT(ble_gap_test_event.type == 0xff);
+    }
 }
 
 static void
@@ -2893,9 +2904,6 @@ TEST_CASE(ble_gap_test_case_update_timeout)
     /* L2CAP - Local unsupported; L2CAP timeout. */
     ble_gap_test_util_update_l2cap_tmo(&params, BLE_ERR_UNKNOWN_HCI_CMD, 0, 0);
 
-    /* L2CAP - Local unsupported; LL timeout. */
-    ble_gap_test_util_update_l2cap_tmo(&params, BLE_ERR_UNKNOWN_HCI_CMD, 0, 1);
-
     /* L2CAP - Remote unsupported; L2CAP timeout. */
     ble_gap_test_util_update_l2cap_tmo(&params, 0, BLE_ERR_UNSUPP_REM_FEATURE,
                                        0);


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services