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-newtmgr.git

commit e81640820e32c47119b6a9c43e202dcdb6ae0487
Author: Szymon Janc <[email protected]>
AuthorDate: Thu Oct 22 00:29:21 2026 +0200

    nmxact/nmble: Fix ErrCodeToString for ATT and SM error codes
    
    ErrCodeToString had empty cases for the ATT, SM (local) and SM (peer)
    error code ranges, so every such status was reported as "unknown"
    even though AttErrCodeStringMap and SmErrCodeStringMap define names
    for them. Users saw e.g. "indicates error: unknown (261)" instead of
    "insufficient authentication" when a GATT operation or pairing
    failed.
    
    Look the codes up in the corresponding maps. L2CAP codes still have
    no names and are reported as "unknown" as before.
    
    Assisted-by: Claude:claude-opus-5-5
---
 nmxact/nmble/ble_proto.go      |  6 ++++++
 nmxact/nmble/ble_proto_test.go | 24 ++++++++++++++++++++++++
 2 files changed, 30 insertions(+)

diff --git a/nmxact/nmble/ble_proto.go b/nmxact/nmble/ble_proto.go
index 37243ae..ca8c3d0 100644
--- a/nmxact/nmble/ble_proto.go
+++ b/nmxact/nmble/ble_proto.go
@@ -1463,12 +1463,18 @@ func ErrCodeToString(e int) string {
 
        switch {
        case e >= ERR_CODE_SM_PEER_BASE:
+               s = SmErrCodeStringMap[e-ERR_CODE_SM_PEER_BASE]
+
        case e >= ERR_CODE_SM_US_BASE:
+               s = SmErrCodeStringMap[e-ERR_CODE_SM_US_BASE]
+
        case e >= ERR_CODE_L2C_BASE:
        case e >= ERR_CODE_HCI_BASE:
                s = HciErrCodeStringMap[e-ERR_CODE_HCI_BASE]
 
        case e >= ERR_CODE_ATT_BASE:
+               s = AttErrCodeStringMap[e-ERR_CODE_ATT_BASE]
+
        default:
                s = ErrCodeStringMap[e]
        }
diff --git a/nmxact/nmble/ble_proto_test.go b/nmxact/nmble/ble_proto_test.go
index 0da845b..b6b6a17 100644
--- a/nmxact/nmble/ble_proto_test.go
+++ b/nmxact/nmble/ble_proto_test.go
@@ -279,6 +279,14 @@ func TestErrCodeToString(t *testing.T) {
                        HciErrCodeStringMap[ERR_CODE_HCI_REM_USER_CONN_TERM]},
                {ERR_CODE_HCI_BASE + 0xfe, "unknown"},
                {ERR_CODE_L2C_BASE + 1, "unknown"},
+               {ERR_CODE_ATT_BASE + ERR_CODE_ATT_INSUFFICIENT_ENC,
+                       "insufficient encryption"},
+               {ERR_CODE_ATT_BASE, "unknown"},
+               {ERR_CODE_ATT_BASE + 0xfe, "unknown"},
+               {ERR_CODE_SM_US_BASE + ERR_CODE_SM_ERR_PASSKEY, "passkey"},
+               {ERR_CODE_SM_PEER_BASE + ERR_CODE_SM_ERR_DHKEY,
+                       "dhkey check failed"},
+               {ERR_CODE_SM_PEER_BASE + 0x100, "unknown"},
        }
 
        for _, tt := range tests {
@@ -293,6 +301,22 @@ func TestErrCodeToString(t *testing.T) {
                        t.Errorf("ErrCodeToString(%d) = %q, want %q", code, 
got, name)
                }
        }
+       for code, name := range AttErrCodeStringMap {
+               if got := ErrCodeToString(ERR_CODE_ATT_BASE + code); got != 
name {
+                       t.Errorf("ErrCodeToString(att %d) = %q, want %q", code, 
got,
+                               name)
+               }
+       }
+       for code, name := range SmErrCodeStringMap {
+               for _, base := range []int{ERR_CODE_SM_US_BASE,
+                       ERR_CODE_SM_PEER_BASE} {
+
+                       if got := ErrCodeToString(base + code); got != name {
+                               t.Errorf("ErrCodeToString(%#x) = %q, want %q", 
base+code,
+                                       got, name)
+                       }
+               }
+       }
        for code, name := range HciErrCodeStringMap {
                if got := ErrCodeToString(ERR_CODE_HCI_BASE + code); got != 
name {
                        t.Errorf("ErrCodeToString(hci %d) = %q, want %q", code, 
got,

Reply via email to