Skip to content

[Bugfix] HCI response to disconnect of unknown ID should return success.#1130

Merged
h2zero merged 1 commit intomasterfrom
bugfix/disconnect-unk-conn-id
Mar 28, 2026
Merged

[Bugfix] HCI response to disconnect of unknown ID should return success.#1130
h2zero merged 1 commit intomasterfrom
bugfix/disconnect-unk-conn-id

Conversation

@h2zero
Copy link
Copy Markdown
Owner

@h2zero h2zero commented Mar 27, 2026

  • Update macro use to use conversion macros.

Summary by CodeRabbit

  • Bug Fixes
    • Improved handling of connection and encryption edge cases to make Bluetooth connections more reliable and reduce spurious disconnect errors by treating an additional termination outcome as non-fatal.
  • Diagnostics
    • Enhanced failure logging to include both numeric and textual codes for clearer troubleshooting.

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Mar 27, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 1be89019-0405-43e0-a83e-daf4d58c9b73

📥 Commits

Reviewing files that changed from the base of the PR and between 7bc8daf and efc8dc2.

📒 Files selected for processing (2)
  • src/NimBLEClient.cpp
  • src/NimBLEServer.cpp
🚧 Files skipped from review as they are similar to previous changes (2)
  • src/NimBLEServer.cpp
  • src/NimBLEClient.cpp

📝 Walkthrough

Walkthrough

Arrr — Replaced raw HCI error-constant arithmetic with BLE_HS_HCI_ERR(...) checks in client security/connection and gap-handling paths; enhanced secureConnection failure logging to include numeric and string codes; changed client and server disconnect logic to treat BLE_HS_HCI_ERR(BLE_ERR_UNK_CONN_ID) (and some other codes) as non‑fatal and adjust returned result accordingly.

Changes

Cohort / File(s) Summary
Client connection & error handling
src/NimBLEClient.cpp
Replaced raw HCI base+error arithmetic with BLE_HS_HCI_ERR(<BLE_ERR_...>) comparisons in secureConnection, handleGapEvent, and disconnect; added NimBLEUtils::returnCodeToString() to secureConnection failure logging; reworked disconnect to a switch(rc) that treats several return codes as non‑fatal and sets m_connStatus only on successful call.
Server disconnect behavior
src/NimBLEServer.cpp
Refactored disconnect return-code handling to switch(rc), treating 0, BLE_HS_ENOTCONN, BLE_HS_EALREADY, and BLE_HS_HCI_ERR(BLE_ERR_UNK_CONN_ID) as non‑fatal (returning true), and logging+returning false for other non‑zero codes.

Sequence Diagram(s)

(omitted)

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Poem

⚓ Arrr, the codes be tidy, no more crude sums,
Errors now named where the HCI wind hums,
Logs shout the number and the tale it tells,
Disconnects loosen ropes and ring the bells,
Avast — smoother seas for BLE's salt drums!

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main bugfix: updating HCI error handling for unknown connection IDs to return success, which aligns with the core changes in both NimBLEClient.cpp and NimBLEServer.cpp.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch bugfix/disconnect-unk-conn-id

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@h2zero h2zero force-pushed the bugfix/disconnect-unk-conn-id branch 2 times, most recently from 1cb9106 to 7bc8daf Compare March 28, 2026 00:25
@h2zero h2zero force-pushed the bugfix/disconnect-unk-conn-id branch from 7bc8daf to efc8dc2 Compare March 28, 2026 17:29
@h2zero
Copy link
Copy Markdown
Owner Author

h2zero commented Mar 28, 2026

@coderabbitai review

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Mar 28, 2026

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@h2zero h2zero merged commit 0dce7fb into master Mar 28, 2026
42 checks passed
@h2zero h2zero deleted the bugfix/disconnect-unk-conn-id branch March 28, 2026 21:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant