This is an automated email from the ASF dual-hosted git repository.

sjanc pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-nimble.git


The following commit(s) were added to refs/heads/master by this push:
     new 3242e6756 apps/bttester: implement ATT timeout event
3242e6756 is described below

commit 3242e6756cd81265162552c0a6a9d304804a3a63
Author: Piotr Narajowski <[email protected]>
AuthorDate: Mon Feb 23 17:10:42 2026 +0100

    apps/bttester: implement ATT timeout event
    
    Implement a dedicated tester event for reporting timeout
    of gatt procedure to auto-pts. Whenever a gatt procedure
    will timeout, application will be notified and att_timeout
    event will be issued
    
    Fix error status reading in callbacks
    When casting the value of status field from struct ble_gatt_error
    to uint8_t, the error code base was being ignored. As a result, all
    errors were interpreted as ATT errors, which made it impossible to
    detect other errors e.g. BLE_HS_ETIMEOUT.
---
 apps/bttester/src/btp/btp_gattc.h |   4 ++
 apps/bttester/src/btp_gatt_cl.c   | 147 ++++++++++++++++++++++++++++++++++----
 2 files changed, 137 insertions(+), 14 deletions(-)

diff --git a/apps/bttester/src/btp/btp_gattc.h 
b/apps/bttester/src/btp/btp_gattc.h
index df90ef0d9..fcdb53a9d 100644
--- a/apps/bttester/src/btp/btp_gattc.h
+++ b/apps/bttester/src/btp/btp_gattc.h
@@ -250,3 +250,7 @@ struct btp_gattc_notification_ev {
 } __packed;
 
 #define BTP_GATTC_READ_MULTIPLE_VAR_RP    0x91
+#define BTP_GATTC_EV_ATT_TIMEOUT          0x92
+struct btp_gattc_ev_att_timeout {
+    ble_addr_t address;
+} __packed;
diff --git a/apps/bttester/src/btp_gatt_cl.c b/apps/bttester/src/btp_gatt_cl.c
index 2f0591cdc..a5732c8ef 100644
--- a/apps/bttester/src/btp_gatt_cl.c
+++ b/apps/bttester/src/btp_gatt_cl.c
@@ -118,6 +118,21 @@ read_destroy()
     gatt_buf_clear();
 }
 
+static void
+att_timeout(uint16_t conn_handle)
+{
+    struct btp_gattc_ev_att_timeout ev;
+    struct ble_gap_conn_desc desc;
+    int rc;
+
+    rc = ble_gap_conn_find(conn_handle, &desc);
+    assert(rc == 0);
+
+    memcpy(&ev.address, &desc.peer_id_addr, sizeof(ev.address));
+    tester_event(BTP_SERVICE_ID_GATTC, BTP_GATTC_EV_ATT_TIMEOUT,
+                 (uint8_t *)&ev, sizeof(ev));
+}
+
 static int
 tester_mtu_exchanged_ev(uint16_t conn_handle,
                         const struct ble_gatt_error *error,
@@ -185,11 +200,20 @@ disc_prim_svcs_cb(uint16_t conn_handle,
     uint8_t uuid_length;
     struct os_mbuf *buf = os_msys_get(0, 0);
     uint8_t opcode = (uint8_t) (int) arg;
-    uint8_t err = (uint8_t) error->status;
+    uint8_t err = 0;
     int rc = 0;
 
     SYS_LOG_DBG("");
 
+    if (error->status == BLE_HS_ETIMEOUT) {
+        att_timeout(conn_handle);
+        goto free;
+    } else if ((error->status & 0xFF00) == BLE_HS_ERR_ATT_BASE) {
+        err = (uint8_t)error->status;
+    } else if (error->status != 0) {
+        err = BLE_ATT_ERR_UNLIKELY;
+    }
+
     if (ble_gap_conn_find(conn_handle, &conn)) {
         goto free;
     }
@@ -314,13 +338,22 @@ find_included_cb(uint16_t conn_handle,
     const ble_uuid_any_t *uuid;
     int service_handle = (int) arg;
     uint8_t uuid_length;
-    uint8_t err = (uint8_t) error->status;
+    uint8_t err = 0;
     struct os_mbuf *buf = os_msys_get(0, 0);
     struct ble_gap_conn_desc conn;
     int rc = 0;
 
     SYS_LOG_DBG("");
 
+    if (error->status == BLE_HS_ETIMEOUT) {
+        att_timeout(conn_handle);
+        goto free;
+    } else if ((error->status & 0xFF00) == BLE_HS_ERR_ATT_BASE) {
+        err = (uint8_t)error->status;
+    } else if (error->status != 0) {
+        err = BLE_ATT_ERR_UNLIKELY;
+    }
+
     if (ble_gap_conn_find(conn_handle, &conn)) {
         rc = BLE_HS_EINVAL;
         goto free;
@@ -427,12 +460,22 @@ disc_chrc_cb(uint16_t conn_handle,
     const ble_uuid_any_t *uuid;
     uint8_t uuid_length;
     uint8_t opcode = (uint8_t) (int) arg;
-    uint8_t err = (uint8_t) error->status;
+    uint8_t err = 0;
     struct os_mbuf *buf = os_msys_get(0, 0);
     struct ble_gap_conn_desc conn;
     int rc = 0;
 
-    SYS_LOG_DBG("");
+    SYS_LOG_DBG("status=%d", error->status);
+
+    if (error->status == BLE_HS_ETIMEOUT) {
+        att_timeout(conn_handle);
+        goto free;
+    } else if ((error->status & 0xFF00) == BLE_HS_ERR_ATT_BASE) {
+        err = (uint8_t)error->status;
+    } else if (error->status != 0) {
+        err = BLE_ATT_ERR_UNLIKELY;
+    }
+
     if (ble_gap_conn_find(conn_handle, &conn)) {
         goto free;
     }
@@ -578,12 +621,21 @@ disc_all_desc_cb(uint16_t conn_handle,
     struct btp_gatt_descriptor *dsc;
     const ble_uuid_any_t *uuid;
     uint8_t uuid_length;
-    uint8_t err = (uint8_t) error->status;
+    uint8_t err = 0;
     struct os_mbuf *buf = os_msys_get(0, 0);
     struct ble_gap_conn_desc conn;
     int rc = 0;
 
-    SYS_LOG_DBG("");
+    SYS_LOG_DBG("status=%d", error->status);
+
+    if (error->status == BLE_HS_ETIMEOUT) {
+        att_timeout(conn_handle);
+        goto free;
+    } else if ((error->status & 0xFF00) == BLE_HS_ERR_ATT_BASE) {
+        err = (uint8_t)error->status;
+    } else if (error->status != 0) {
+        err = BLE_ATT_ERR_UNLIKELY;
+    }
 
     if (ble_gap_conn_find(conn_handle, &conn)) {
         rc = BLE_HS_EINVAL;
@@ -691,6 +743,16 @@ read_cb(uint16_t conn_handle,
     struct os_mbuf *buf = os_msys_get(0, 0);
     struct ble_gap_conn_desc conn;
     int rc = 0;
+    uint8_t err = 0;
+
+    if (error->status == BLE_HS_ETIMEOUT) {
+        att_timeout(conn_handle);
+        goto free;
+    } else if ((error->status & 0xFF00) == BLE_HS_ERR_ATT_BASE) {
+        err = (uint8_t)error->status;
+    } else if (error->status != 0) {
+        err = BLE_ATT_ERR_UNLIKELY;
+    }
 
     if (ble_gap_conn_find(conn_handle, &conn)) {
         rc = BLE_HS_EINVAL;
@@ -708,7 +770,7 @@ read_cb(uint16_t conn_handle,
     SYS_LOG_DBG("status=%d", error->status);
 
     if (error->status != 0 && error->status != BLE_HS_EDONE) {
-        rp->status = (uint8_t) BLE_HS_ATT_ERR(error->status);
+        rp->status = err;
         rp->data_length = 0;
         tester_event(BTP_SERVICE_ID_GATTC, opcode,
                      buf->om_data, buf->om_len);
@@ -769,7 +831,7 @@ read_uuid_cb(uint16_t conn_handle,
     struct btp_gattc_read_uuid_rp *rp;
     struct btp_gatt_read_uuid_chr *chr;
     uint8_t opcode = (uint8_t) (int) arg;
-    uint8_t err = (uint8_t) error->status;
+    uint8_t err = 0;
     struct os_mbuf *buf = os_msys_get(0, 0);
     struct ble_gap_conn_desc conn;
     int rc = 0;
@@ -777,6 +839,15 @@ read_uuid_cb(uint16_t conn_handle,
 
     SYS_LOG_DBG("status=%d", error->status);
 
+    if (error->status == BLE_HS_ETIMEOUT) {
+        att_timeout(conn_handle);
+        goto free;
+    } else if ((error->status & 0xFF00) == BLE_HS_ERR_ATT_BASE) {
+        err = (uint8_t)error->status;
+    } else if (error->status != 0) {
+        err = BLE_ATT_ERR_UNLIKELY;
+    }
+
     if (ble_gap_conn_find(conn_handle, &conn)) {
         rc = BLE_HS_EINVAL;
         goto free;
@@ -872,14 +943,23 @@ read_long_cb(uint16_t conn_handle,
              void *arg)
 {
     struct btp_gattc_read_rp *rp;
-    uint8_t opcode = (uint8_t) (int) arg;
-    uint8_t err = (uint8_t) error->status;
+    uint8_t opcode = (uint8_t)(int)arg;
     struct os_mbuf *buf = os_msys_get(0, 0);
     struct ble_gap_conn_desc conn;
     int rc = 0;
+    uint8_t err = 0;
 
     SYS_LOG_DBG("status=%d", error->status);
 
+    if (error->status == BLE_HS_ETIMEOUT) {
+        att_timeout(conn_handle);
+        goto free;
+    } else if ((error->status & 0xFF00) == BLE_HS_ERR_ATT_BASE) {
+        err = (uint8_t)error->status;
+    } else if (error->status != 0) {
+        err = BLE_ATT_ERR_UNLIKELY;
+    }
+
     if (ble_gap_conn_find(conn_handle, &conn)) {
         rc = BLE_HS_EINVAL;
         goto free;
@@ -1025,7 +1105,7 @@ write_cb(uint16_t conn_handle, const struct 
ble_gatt_error *error,
          void *arg)
 {
     struct btp_gattc_write_rp *rp;
-    uint8_t err = (uint8_t) error->status;
+    uint8_t err = 0;
     uint8_t opcode = (uint8_t) (int) arg;
     struct os_mbuf *buf = os_msys_get(0, 0);
     struct ble_gap_conn_desc conn;
@@ -1033,6 +1113,15 @@ write_cb(uint16_t conn_handle, const struct 
ble_gatt_error *error,
 
     SYS_LOG_DBG("");
 
+    if (error->status == BLE_HS_ETIMEOUT) {
+        att_timeout(conn_handle);
+        goto free;
+    } else if ((error->status & 0xFF00) == BLE_HS_ERR_ATT_BASE) {
+        err = (uint8_t)error->status;
+    } else if (error->status != 0) {
+        err = BLE_ATT_ERR_UNLIKELY;
+    }
+
     if (ble_gap_conn_find(conn_handle, &conn)) {
         rc = BLE_HS_EINVAL;
         goto free;
@@ -1133,13 +1222,22 @@ reliable_write_cb(uint16_t conn_handle,
                   void *arg)
 {
     struct btp_gattc_write_rp *rp;
-    uint8_t err = (uint8_t) error->status;
+    uint8_t err = 0;
     struct os_mbuf *buf = os_msys_get(0, 0);
     struct ble_gap_conn_desc conn;
     int rc = 0;
 
     SYS_LOG_DBG("");
 
+    if (error->status == BLE_HS_ETIMEOUT) {
+        att_timeout(conn_handle);
+        goto free;
+    } else if ((error->status & 0xFF00) == BLE_HS_ERR_ATT_BASE) {
+        err = (uint8_t)error->status;
+    } else if (error->status != 0) {
+        err = BLE_ATT_ERR_UNLIKELY;
+    }
+
     if (ble_gap_conn_find(conn_handle, &conn)) {
         rc = BLE_HS_EINVAL;
         goto free;
@@ -1210,7 +1308,7 @@ subscribe_cb(uint16_t conn_handle,
              void *arg)
 {
     struct btp_subscribe_rp *rp;
-    uint8_t err = (uint8_t) error->status;
+    uint8_t err = 0;
     uint8_t opcode = (uint8_t) (int) arg;
     struct os_mbuf *buf = os_msys_get(0, 0);
     struct ble_gap_conn_desc conn;
@@ -1218,6 +1316,15 @@ subscribe_cb(uint16_t conn_handle,
 
     SYS_LOG_DBG("");
 
+    if (error->status == BLE_HS_ETIMEOUT) {
+        att_timeout(conn_handle);
+        goto free;
+    } else if ((error->status & 0xFF00) == BLE_HS_ERR_ATT_BASE) {
+        err = (uint8_t)error->status;
+    } else if (error->status != 0) {
+        err = BLE_ATT_ERR_UNLIKELY;
+    }
+
     if (ble_gap_conn_find(conn_handle, &conn)) {
         rc = BLE_HS_EINVAL;
         goto free;
@@ -1375,9 +1482,21 @@ read_var_cb(uint16_t conn_handle,
     struct ble_gap_conn_desc conn;
     uint8_t rp_data_off = 0;
     struct ble_gatt_attr attrs[num_attrs];
+    uint8_t err = 0;
 
     SYS_LOG_DBG("status=%d", error->status);
 
+    if (error->status != 0) {
+        if ((error->status & 0xFF00) == BLE_HS_ERR_ATT_BASE) {
+            err = (uint8_t)error->status;
+        } else if (error->status == BLE_HS_ETIMEOUT) {
+            att_timeout(conn_handle);
+            return 0;
+        } else {
+            err = BLE_ATT_ERR_UNLIKELY;
+        }
+    }
+
     if (ble_gap_conn_find(conn_handle, &conn)) {
         return BTP_STATUS_FAILED;
     }
@@ -1386,7 +1505,7 @@ read_var_cb(uint16_t conn_handle,
 
     memcpy(&rp->address, &conn.peer_ota_addr, sizeof(rp->address));
 
-    rp->status = (uint8_t) BLE_HS_ATT_ERR(error->status);
+    rp->status = err;
 
     if (error->status != 0) {
         rp->data_length = 0;

Reply via email to