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

janc 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 64067f51 nimble/gatts: Add check for RFU bits
64067f51 is described below

commit 64067f5168bd4de097b7830a078862a5df95d9a5
Author: Roshan <[email protected]>
AuthorDate: Tue Dec 12 09:20:41 2023 +0530

    nimble/gatts: Add check for RFU bits
---
 nimble/host/include/host/ble_att.h |  3 +++
 nimble/host/src/ble_gatt_priv.h    |  5 +++++
 nimble/host/src/ble_gatts.c        | 13 +++++++++----
 3 files changed, 17 insertions(+), 4 deletions(-)

diff --git a/nimble/host/include/host/ble_att.h 
b/nimble/host/include/host/ble_att.h
index 5a3a2a1f..bfd7adf1 100644
--- a/nimble/host/include/host/ble_att.h
+++ b/nimble/host/include/host/ble_att.h
@@ -110,6 +110,9 @@ struct os_mbuf;
 /**Insufficient Resources to complete the request. */
 #define BLE_ATT_ERR_INSUFFICIENT_RES        0x11
 
+/**Requested value is not allowed. */
+#define BLE_ATT_ERR_VALUE_NOT_ALLOWED       0x13
+
 /** @} */
 
 /**
diff --git a/nimble/host/src/ble_gatt_priv.h b/nimble/host/src/ble_gatt_priv.h
index ba0b8067..eb778293 100644
--- a/nimble/host/src/ble_gatt_priv.h
+++ b/nimble/host/src/ble_gatt_priv.h
@@ -89,6 +89,11 @@ extern STATS_SECT_DECL(ble_gatts_stats) ble_gatts_stats;
 #define BLE_GATT_CHR_DECL_SZ_16         5
 #define BLE_GATT_CHR_DECL_SZ_128        19
 #define BLE_GATT_CHR_CLI_SUP_FEAT_SZ    1
+/**
+ * For now only 3 bits in first octet are defined
+ *
+ */
+#define BLE_GATT_CHR_CLI_SUP_FEAT_MASK  7
 
 typedef uint8_t ble_gatts_conn_flags;
 
diff --git a/nimble/host/src/ble_gatts.c b/nimble/host/src/ble_gatts.c
index 2f95b70e..2c18cc4a 100644
--- a/nimble/host/src/ble_gatts.c
+++ b/nimble/host/src/ble_gatts.c
@@ -1620,20 +1620,20 @@ ble_gatts_peer_cl_sup_feat_update(uint16_t conn_handle, 
struct os_mbuf *om)
     BLE_HS_LOG(DEBUG, "");
 
     if (!om) {
-        return BLE_HS_EINVAL;
+        return BLE_ATT_ERR_INSUFFICIENT_RES;
     }
 
     ble_hs_lock();
     conn = ble_hs_conn_find(conn_handle);
     if (conn == NULL) {
-        rc = BLE_HS_ENOTCONN;
+        rc = BLE_ATT_ERR_UNLIKELY;
         goto done;
     }
     if (om->om_len == 0) {
         /* Nothing to do */
         goto done;
     } else if (os_mbuf_len(om) > BLE_ATT_ATTR_MAX_LEN) {
-        rc = BLE_HS_ENOMEM;
+        rc = BLE_ATT_ERR_INSUFFICIENT_RES;
         goto done;
     }
 
@@ -1647,10 +1647,15 @@ ble_gatts_peer_cl_sup_feat_update(uint16_t conn_handle, 
struct os_mbuf *om)
              */
             if (conn->bhc_gatt_svr.peer_cl_sup_feat[feat_idx] >
                 om->om_data[i]) {
-                rc = BLE_HS_EINVAL;
+                rc = BLE_ATT_ERR_VALUE_NOT_ALLOWED;
                 goto done;
             }
 
+            /* All RFU bits should be unset */
+            if (feat_idx == 0) {
+                om->om_data[i] &= BLE_GATT_CHR_CLI_SUP_FEAT_MASK;
+            }
+
             conn->bhc_gatt_svr.peer_cl_sup_feat[feat_idx] |= om->om_data[i];
 
             feat_idx++;

Reply via email to