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 812038c5d2f16a60b58b96758356e78ac5b27e6c
Author: Piotr Narajowski <[email protected]>
AuthorDate: Fri Mar 13 14:57:41 2026 +0100

    nimble/l2cap: remove unnecessary error base conversion
    
    This removes ble_l2cap_sig_coc_err2ble_hs_err method and it's usages.
    There is no need to convert an L2CAP connection response result to
    Host error code.
    L2CAP coc conn unit tests are updated accordingly - expected app status
    has l2cap base now.
---
 nimble/host/src/ble_l2cap_sig.c       | 33 ++-------------------------------
 nimble/host/test/src/ble_l2cap_test.c | 12 ++++++------
 2 files changed, 8 insertions(+), 37 deletions(-)

diff --git a/nimble/host/src/ble_l2cap_sig.c b/nimble/host/src/ble_l2cap_sig.c
index a38a7c51f..820ecff02 100644
--- a/nimble/host/src/ble_l2cap_sig.c
+++ b/nimble/host/src/ble_l2cap_sig.c
@@ -644,35 +644,6 @@ ble_l2cap_sig_update(uint16_t conn_handle, struct 
ble_l2cap_sig_update_params *p
 
 #if MYNEWT_VAL(BLE_L2CAP_COC_MAX_NUM) != 0
 
-static int
-ble_l2cap_sig_coc_err2ble_hs_err(uint16_t l2cap_coc_err)
-{
-    switch (l2cap_coc_err) {
-    case BLE_L2CAP_COC_ERR_CONNECTION_SUCCESS:
-        return 0;
-    case BLE_L2CAP_COC_ERR_UNKNOWN_LE_PSM:
-        return BLE_HS_ENOTSUP;
-    case BLE_L2CAP_COC_ERR_NO_RESOURCES:
-        return BLE_HS_ENOMEM;
-    case BLE_L2CAP_COC_ERR_INSUFFICIENT_AUTHEN:
-        return BLE_HS_EAUTHEN;
-    case BLE_L2CAP_COC_ERR_INSUFFICIENT_AUTHOR:
-        return BLE_HS_EAUTHOR;
-    case BLE_L2CAP_COC_ERR_INSUFFICIENT_KEY_SZ:
-        return BLE_HS_EENCRYPT_KEY_SZ;
-    case BLE_L2CAP_COC_ERR_INSUFFICIENT_ENC:
-        return BLE_HS_EENCRYPT;
-    case BLE_L2CAP_COC_ERR_INVALID_SOURCE_CID:
-        return BLE_HS_EREJECT;
-    case BLE_L2CAP_COC_ERR_SOURCE_CID_ALREADY_USED:
-        return BLE_HS_EALREADY;
-    case BLE_L2CAP_COC_ERR_UNACCEPTABLE_PARAMETERS:
-        return BLE_HS_EINVAL;
-    default:
-        return BLE_HS_EUNKNOWN;
-    }
-}
-
 static int
 ble_l2cap_sig_ble_hs_err2coc_err(uint16_t ble_hs_err)
 {
@@ -1151,7 +1122,7 @@ ble_l2cap_sig_credit_base_con_rsp_rx(uint16_t conn_handle,
     rsp = (struct ble_l2cap_sig_credit_base_connect_rsp *)(*om)->om_data;
 
     if (rsp->result) {
-        rc = ble_l2cap_sig_coc_err2ble_hs_err(le16toh(rsp->result));
+        rc = BLE_HS_L2C_ERR(le16toh(rsp->result));
         /* Below results means that some of the channels has not been created
          * and we have to look closer into the response.
          * Any other results means that all the connections has been refused.
@@ -1344,7 +1315,7 @@ ble_l2cap_sig_coc_rsp_rx(uint16_t conn_handle, struct 
ble_l2cap_sig_hdr *hdr,
     chan = proc->connect.chan[0];
 
     if (rsp->result) {
-        rc = ble_l2cap_sig_coc_err2ble_hs_err(le16toh(rsp->result));
+        rc = BLE_HS_L2C_ERR(le16toh(rsp->result));
         goto done;
     }
 
diff --git a/nimble/host/test/src/ble_l2cap_test.c 
b/nimble/host/test/src/ble_l2cap_test.c
index d1d02f643..9eba7e21a 100644
--- a/nimble/host/test/src/ble_l2cap_test.c
+++ b/nimble/host/test/src/ble_l2cap_test.c
@@ -700,7 +700,7 @@ ble_l2cap_test_event(struct ble_l2cap_event *event, void 
*arg)
     ev->handled = 1;
     switch (event->type) {
     case BLE_L2CAP_EVENT_COC_CONNECTED:
-        assert(ev->app_status == event->connect.status);
+        assert(ev->app_status == (uint8_t)event->connect.status);
         t->chan[0] = event->connect.chan;
         return 0;
     case BLE_L2CAP_EVENT_COC_DISCONNECTED:
@@ -1125,7 +1125,7 @@ 
TEST_CASE_SELF(ble_l2cap_test_case_sig_coc_conn_invalid_psm)
     t.expected_num_iters = 1;
 
     t.event[0].type = BLE_L2CAP_EVENT_COC_CONNECTED;
-    t.event[0].app_status = BLE_HS_ENOTSUP;
+    t.event[0].app_status = BLE_L2CAP_COC_ERR_UNKNOWN_LE_PSM;
     t.event[0].l2cap_status = BLE_L2CAP_COC_ERR_UNKNOWN_LE_PSM;
 
     ble_l2cap_test_coc_connect(&t);
@@ -1147,7 +1147,7 @@ 
TEST_CASE_SELF(ble_l2cap_test_case_sig_coc_conn_out_of_resource)
     t.expected_num_iters = 1;
 
     t.event[0].type = BLE_L2CAP_EVENT_COC_CONNECTED;
-    t.event[0].app_status = BLE_HS_ENOMEM;
+    t.event[0].app_status = BLE_L2CAP_COC_ERR_NO_RESOURCES;
     t.event[0].l2cap_status = BLE_L2CAP_COC_ERR_NO_RESOURCES;
 
     ble_l2cap_test_coc_connect(&t);
@@ -1168,7 +1168,7 @@ 
TEST_CASE_SELF(ble_l2cap_test_case_sig_coc_conn_invalid_cid)
     t.expected_num_of_ev = 1;
 
     t.event[0].type = BLE_L2CAP_EVENT_COC_CONNECTED;
-    t.event[0].app_status = BLE_HS_EREJECT;
+    t.event[0].app_status = BLE_L2CAP_COC_ERR_INVALID_SOURCE_CID;
     t.event[0].l2cap_status = BLE_L2CAP_COC_ERR_INVALID_SOURCE_CID;
 
     ble_l2cap_test_coc_connect(&t);
@@ -1188,7 +1188,7 @@ 
TEST_CASE_SELF(ble_l2cap_test_case_sig_coc_conn_insuff_authen)
     t.expected_num_of_ev = 1;
 
     t.event[0].type = BLE_L2CAP_EVENT_COC_CONNECTED;
-    t.event[0].app_status = BLE_HS_EAUTHEN;
+    t.event[0].app_status = BLE_L2CAP_COC_ERR_INSUFFICIENT_AUTHEN;
     t.event[0].l2cap_status = BLE_L2CAP_COC_ERR_INSUFFICIENT_AUTHEN;
 
     ble_l2cap_test_coc_connect(&t);
@@ -1208,7 +1208,7 @@ 
TEST_CASE_SELF(ble_l2cap_test_case_sig_coc_conn_insuff_author)
     t.expected_num_of_ev = 1;
 
     t.event[0].type = BLE_L2CAP_EVENT_COC_CONNECTED;
-    t.event[0].app_status = BLE_HS_EAUTHOR;
+    t.event[0].app_status = BLE_L2CAP_COC_ERR_INSUFFICIENT_AUTHOR;
     t.event[0].l2cap_status = BLE_L2CAP_COC_ERR_INSUFFICIENT_AUTHOR;
 
     ble_l2cap_test_coc_connect(&t);

Reply via email to