Skip to content

[Feature] Expose L2CAP CoC disconnect + conn handle in NimBLEL2CAPChannel #391

@mickeyl

Description

@mickeyl

Motivation

Today, when a server detects a protocol violation (e.g., oversized SDU/PDU, malformed framing, abuse), there’s no public API to actively terminate the L2CAP CoC from the NimBLEL2CAPChannel object. The NimBLE host already supports this (ble_l2cap_disconnect() / ble_l2cap_get_conn_handle()), but esp‑nimble‑cpp doesn’t surface it. This forces applications either to keep the link alive (risking repeated abuse) or to terminate the entire GAP connection via NimBLEServer::disconnect (too coarse). A channel‑level disconnect is the correct and efficient response for DoS‑style abuse in L2CAP CoC services.

Proposed API

  • Add to NimBLEL2CAPChannel:
    • bool disconnect();
      Calls ble_l2cap_disconnect(channel) and returns success/failure.
    • uint16_t getConnHandle() const;
      Returns ble_l2cap_get_conn_handle(channel) (or BLE_HS_CONN_HANDLE_NONE if not connected).
    • Optional: bool getChanInfo(ble_l2cap_chan_info& info) const; for callers that need MTU or PSM without re-querying host internals.

Use case

  • L2CAP CoC server detects oversized payloads or invalid framing in onRead() and cleanly disconnects only that channel, leaving the BLE link intact for other services.

This keeps esp‑nimble‑cpp aligned with NimBLE capabilities, improves robustness/security, and avoids application‑level hacks.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions