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

commit 2ac35fcaa60ace24af58c9c83a808c4dcdb41533
Author: Szymon Janc <[email protected]>
AuthorDate: Wed Oct 7 18:07:38 2026 +0200

    nimble/ll/test: Add tests for subrate HCI commands length check
    
    Verify that HCI LE Set Default Subrate and LE Subrate Request commands
    with invalid parameters length are rejected.
    
    Assisted-by: Claude:claude-opus-5-5
---
 nimble/controller/test/src/ble_ll_hci_test.c | 85 ++++++++++++++++++++++++++++
 nimble/controller/test/src/ble_ll_test.c     |  2 +
 nimble/controller/test/syscfg.yml            |  1 +
 3 files changed, 88 insertions(+)

diff --git a/nimble/controller/test/src/ble_ll_hci_test.c 
b/nimble/controller/test/src/ble_ll_hci_test.c
new file mode 100644
index 000000000..996c3a5c9
--- /dev/null
+++ b/nimble/controller/test/src/ble_ll_hci_test.c
@@ -0,0 +1,85 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+#include <stdint.h>
+#include <string.h>
+#include <nimble/ble.h>
+#include <nimble/hci_common.h>
+#include <testutil/testutil.h>
+#include "ble_ll_conn_priv.h"
+
+/* Handle of a connection that does not exist */
+#define TEST_CONN_HANDLE (0x0abc)
+
+#if MYNEWT_VAL(BLE_LL_CFG_FEAT_LL_ENHANCED_CONN_UPDATE)
+TEST_CASE_SELF(test_ll_hci_set_default_subrate_len)
+{
+    struct ble_hci_le_set_default_subrate_cp cmd = {
+        .subrate_min = htole16(1),
+        .subrate_max = htole16(2),
+        .max_latency = htole16(0),
+        .cont_num = htole16(0),
+        .supervision_tmo = htole16(100),
+    };
+    uint8_t rsplen = 0;
+    int rc;
+
+    rc = ble_ll_conn_hci_set_default_subrate((uint8_t *)&cmd, 0, NULL, 
&rsplen);
+    TEST_ASSERT(rc == BLE_ERR_INV_HCI_CMD_PARMS);
+
+    rc = ble_ll_conn_hci_set_default_subrate((uint8_t *)&cmd, sizeof(cmd) - 1,
+                                             NULL, &rsplen);
+    TEST_ASSERT(rc == BLE_ERR_INV_HCI_CMD_PARMS);
+
+    rc = ble_ll_conn_hci_set_default_subrate((uint8_t *)&cmd, sizeof(cmd),
+                                             NULL, &rsplen);
+    TEST_ASSERT(rc == 0);
+}
+
+TEST_CASE_SELF(test_ll_hci_subrate_req_len)
+{
+    struct ble_hci_le_subrate_req_cp cmd = {
+        .conn_handle = htole16(TEST_CONN_HANDLE),
+        .subrate_min = htole16(1),
+        .subrate_max = htole16(2),
+        .max_latency = htole16(0),
+        .cont_num = htole16(0),
+        .supervision_tmo = htole16(100),
+    };
+    uint8_t rsplen = 0;
+    int rc;
+
+    rc = ble_ll_conn_hci_subrate_req((uint8_t *)&cmd, 0, NULL, &rsplen);
+    TEST_ASSERT(rc == BLE_ERR_INV_HCI_CMD_PARMS);
+
+    rc = ble_ll_conn_hci_subrate_req((uint8_t *)&cmd, sizeof(cmd) - 1, NULL, 
&rsplen);
+    TEST_ASSERT(rc == BLE_ERR_INV_HCI_CMD_PARMS);
+
+    rc = ble_ll_conn_hci_subrate_req((uint8_t *)&cmd, sizeof(cmd), NULL, 
&rsplen);
+    TEST_ASSERT(rc == BLE_ERR_UNK_CONN_ID);
+}
+#endif
+
+TEST_SUITE(ble_ll_hci_test_suite)
+{
+#if MYNEWT_VAL(BLE_LL_CFG_FEAT_LL_ENHANCED_CONN_UPDATE)
+    test_ll_hci_set_default_subrate_len();
+    test_ll_hci_subrate_req_len();
+#endif
+}
diff --git a/nimble/controller/test/src/ble_ll_test.c 
b/nimble/controller/test/src/ble_ll_test.c
index 93e472db3..7b0fadec1 100644
--- a/nimble/controller/test/src/ble_ll_test.c
+++ b/nimble/controller/test/src/ble_ll_test.c
@@ -28,6 +28,7 @@ TEST_SUITE_DECL(ble_ll_csa2_test_suite);
 TEST_SUITE_DECL(ble_ll_isoal_test_suite);
 TEST_SUITE_DECL(ble_ll_iso_test_suite);
 TEST_SUITE_DECL(ble_ll_cs_drbg_test_suite);
+TEST_SUITE_DECL(ble_ll_hci_test_suite);
 
 int
 main(int argc, char **argv)
@@ -38,6 +39,7 @@ main(int argc, char **argv)
     ble_ll_isoal_test_suite();
     ble_ll_iso_test_suite();
     ble_ll_cs_drbg_test_suite();
+    ble_ll_hci_test_suite();
 
     return tu_any_failed;
 }
diff --git a/nimble/controller/test/syscfg.yml 
b/nimble/controller/test/syscfg.yml
index cf6a5de8e..46f0920de 100644
--- a/nimble/controller/test/syscfg.yml
+++ b/nimble/controller/test/syscfg.yml
@@ -20,6 +20,7 @@ syscfg.vals:
     BLE_LL_CFG_FEAT_LE_CSA2: 1
     BLE_LL_ISO: 1
     BLE_VERSION: 54
+    BLE_CONN_SUBRATING: 1
 
     # Prevent priority conflict with controller task.
     MCU_TIMER_POLLER_PRIO: 1

Reply via email to