mynewt-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From GitBox <...@apache.org>
Subject [GitHub] rymanluk closed pull request #736: nimble/att: Fix for PTS issue reported in MYNEWT-886
Date Thu, 01 Jan 1970 00:00:00 GMT
rymanluk closed pull request #736: nimble/att: Fix for PTS issue reported in MYNEWT-886
URL: https://github.com/apache/mynewt-core/pull/736
 
 
   

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/net/nimble/host/src/ble_att.c b/net/nimble/host/src/ble_att.c
index 774444ab0..94f6f41ed 100644
--- a/net/nimble/host/src/ble_att.c
+++ b/net/nimble/host/src/ble_att.c
@@ -461,6 +461,22 @@ ble_att_chan_mtu(const struct ble_l2cap_chan *chan)
     return mtu;
 }
 
+static void
+ble_att_rx_handle_unknown_request(uint8_t op, uint16_t conn_handle,
+                                  struct os_mbuf **om)
+{
+    /* If this is command (bit6 is set to 1), do nothing */
+    if (op & 0x40) {
+        return;
+    }
+
+    os_mbuf_adj(*om, OS_MBUF_PKTLEN(*om));
+    ble_att_svr_tx_error_rsp(conn_handle, *om, op, 0,
+                             BLE_ATT_ERR_REQ_NOT_SUPPORTED);
+
+    *om = NULL;
+}
+
 static int
 ble_att_rx(struct ble_l2cap_chan *chan)
 {
@@ -485,7 +501,8 @@ ble_att_rx(struct ble_l2cap_chan *chan)
 
     entry = ble_att_rx_dispatch_entry_find(op);
     if (entry == NULL) {
-        return BLE_HS_EINVAL;
+        ble_att_rx_handle_unknown_request(op, conn_handle, om);
+        return BLE_HS_ENOTSUP;
     }
 
     ble_att_inc_rx_stat(op);
@@ -495,6 +512,9 @@ ble_att_rx(struct ble_l2cap_chan *chan)
 
     rc = entry->bde_fn(conn_handle, om);
     if (rc != 0) {
+        if (rc == BLE_HS_ENOTSUP) {
+            ble_att_rx_handle_unknown_request(op, conn_handle, om);
+        }
         return rc;
     }
 
diff --git a/net/nimble/host/src/ble_att_priv.h b/net/nimble/host/src/ble_att_priv.h
index e85a1c695..8ab15b101 100644
--- a/net/nimble/host/src/ble_att_priv.h
+++ b/net/nimble/host/src/ble_att_priv.h
@@ -222,6 +222,9 @@ int ble_att_svr_init(void);
 void ble_att_svr_hide_range(uint16_t start_handle, uint16_t end_handle);
 void ble_att_svr_restore_range(uint16_t start_handle, uint16_t end_handle);
 
+int ble_att_svr_tx_error_rsp(uint16_t conn_handle, struct os_mbuf *txom,
+                             uint8_t req_op, uint16_t handle,
+                             uint8_t error_code);
 /*** $clt */
 
 /** An information-data entry in a find information response. */
diff --git a/net/nimble/host/src/ble_att_svr.c b/net/nimble/host/src/ble_att_svr.c
index 4c2680ff8..e2d2c9a80 100644
--- a/net/nimble/host/src/ble_att_svr.c
+++ b/net/nimble/host/src/ble_att_svr.c
@@ -258,7 +258,7 @@ ble_att_svr_check_perms(uint16_t conn_handle, int is_read,
     if (is_read) {
         if (!(entry->ha_flags & BLE_ATT_F_READ)) {
             *out_att_err = BLE_ATT_ERR_READ_NOT_PERMITTED;
-            return BLE_HS_ENOTSUP;
+            return BLE_HS_EREJECT;
         }
 
         enc = entry->ha_flags & BLE_ATT_F_READ_ENC;
@@ -267,7 +267,7 @@ ble_att_svr_check_perms(uint16_t conn_handle, int is_read,
     } else {
         if (!(entry->ha_flags & BLE_ATT_F_WRITE)) {
             *out_att_err = BLE_ATT_ERR_WRITE_NOT_PERMITTED;
-            return BLE_HS_ENOTSUP;
+            return BLE_HS_EREJECT;
         }
 
         enc = entry->ha_flags & BLE_ATT_F_WRITE_ENC;
@@ -573,7 +573,7 @@ ble_att_svr_write_handle(uint16_t conn_handle, uint16_t attr_handle,
     return 0;
 }
 
-static int
+int
 ble_att_svr_tx_error_rsp(uint16_t conn_handle, struct os_mbuf *txom,
                          uint8_t req_op, uint16_t handle, uint8_t error_code)
 {
@@ -1957,7 +1957,7 @@ ble_att_svr_rx_read_group_type(uint16_t conn_handle, struct os_mbuf
**rxom)
     if (!ble_att_svr_is_valid_read_group_type(&uuid.u)) {
         att_err = BLE_ATT_ERR_UNSUPPORTED_GROUP;
         err_handle = start_handle;
-        rc = BLE_HS_ENOTSUP;
+        rc = BLE_HS_EREJECT;
         goto done;
     }
 
diff --git a/net/nimble/host/test/src/ble_att_svr_test.c b/net/nimble/host/test/src/ble_att_svr_test.c
index 0469bfd79..5dd9987cc 100644
--- a/net/nimble/host/test/src/ble_att_svr_test.c
+++ b/net/nimble/host/test/src/ble_att_svr_test.c
@@ -1043,7 +1043,7 @@ TEST_CASE(ble_att_svr_test_write)
 
     rc = ble_hs_test_util_rx_att_write_req(conn_handle, attr_handle,
                                            attr_val, sizeof attr_val);
-    TEST_ASSERT(rc == BLE_HS_ENOTSUP);
+    TEST_ASSERT(rc == BLE_HS_EREJECT);
     ble_hs_test_util_verify_tx_err_rsp(BLE_ATT_OP_WRITE_REQ,
                                        attr_handle,
                                        BLE_ATT_ERR_WRITE_NOT_PERMITTED);
@@ -2052,6 +2052,32 @@ TEST_CASE(ble_att_svr_test_oom)
     TEST_ASSERT_FATAL(rc == 0);
 }
 
+TEST_CASE(ble_att_svr_test_unsupported_req)
+{
+    uint16_t conn_handle;
+    int rc;
+    uint8_t buf[] = {0x3f, 0x00, 0x00, 0x01, 0x02, 0x03};
+
+    conn_handle = ble_att_svr_test_misc_init(0);
+
+    /* Put handle into buf */
+    (*(uint16_t *)&buf[1]) = htole16(conn_handle);
+    rc = ble_hs_test_util_l2cap_rx_payload_flat(conn_handle, BLE_L2CAP_CID_ATT,
+                                                buf, sizeof buf);
+    TEST_ASSERT(rc != 0);
+    ble_hs_test_util_verify_tx_err_rsp(0x3f, 0,
+                                       BLE_ATT_ERR_REQ_NOT_SUPPORTED);
+
+    /* Check for no response when unknown command is sent */
+    buf[0] = 0x4f;
+    rc = ble_hs_test_util_l2cap_rx_payload_flat(conn_handle, BLE_L2CAP_CID_ATT,
+                                                    buf, sizeof buf);
+    TEST_ASSERT(rc != 0);
+
+    /* Ensure no response sent. */
+    TEST_ASSERT(ble_hs_test_util_prev_tx_dequeue() == NULL);
+}
+
 TEST_SUITE(ble_att_svr_suite)
 {
     /* When checking for mbuf leaks, ensure no stale prep entries. */
@@ -2077,6 +2103,7 @@ TEST_SUITE(ble_att_svr_suite)
     ble_att_svr_test_notify();
     ble_att_svr_test_indicate();
     ble_att_svr_test_oom();
+    ble_att_svr_test_unsupported_req();
 }
 
 int


 

----------------------------------------------------------------
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

Mime
View raw message