Kleidos API Search

In development. It changes without notice.

Topic

BLE Connection Management

The state of the link as one coherent snapshot, and the parameters of a connection and of advertising.

kleidos::ble::connection::ConnectionManager gathers what the stack reports (connected, authenticated, size of a packet, subscriptions). Only the stack's task changes it; any task may read it.

See also
BLE Stack Integration

Files

file src/ble/connection/cccd_mailbox.h
The CCCD changes a host makes, carried from the host task to the snapshot.
file src/ble/connection/conn_params.h
BLE connection and advertising timing, and the limits a central may negotiate.
file src/ble/connection/connection_manager.h
Thread-safe snapshot of the active BLE link state.

Classes

struct kleidos::ble::connection::CccdChange
One CCCD change, as the host task saw it. More about kleidos::ble::connection::CccdChange
class kleidos::ble::connection::CccdMailbox
A first-in, first-out ring of CCCD changes; the caller holds the lock. More about kleidos::ble::connection::CccdMailbox
struct kleidos::ble::connection::ConnParamSet
A connection-parameter tuple in native GAP units (mirrors ble_gap_upd_params). More about kleidos::ble::connection::ConnParamSet
struct kleidos::ble::connection::LiveConnParams
The timing a live link runs at: one interval, not a requested range. More about kleidos::ble::connection::LiveConnParams
struct kleidos::ble::connection::Snapshot
Coherent point-in-time view of the active link. More about kleidos::ble::connection::Snapshot
class kleidos::ble::connection::ConnectionManager
Static owner of the live connection snapshot. More about kleidos::ble::connection::ConnectionManager

Enumerations

enum class kleidos::ble::connection::ConnParamPolicy : uint8_t { kleidos::ble::connection::ConnParamPolicy::Accept , kleidos::ble::connection::ConnParamPolicy::Renegotiate , kleidos::ble::connection::ConnParamPolicy::Reject }
Outcome of evaluating a central-requested parameter set against the policy. More about kleidos::ble::connection::ConnParamPolicy
enum class kleidos::ble::connection::LinkTimingStep : uint8_t { kleidos::ble::connection::LinkTimingStep::Settled , kleidos::ble::connection::LinkTimingStep::AskAgain , kleidos::ble::connection::LinkTimingStep::EndLink , kleidos::ble::connection::LinkTimingStep::Keep }
What the peripheral does with a secured link's timing after an update. More about kleidos::ble::connection::LinkTimingStep

Functions

constexpr boolkleidos::ble::connection::timeoutCoversLatency (uint16_t intervalMaxUnits, uint16_t latency, uint16_t timeoutUnits)
Spec coupling check: timeout must outlast (1+latency) connection events.
constexpr ConnParamSetkleidos::ble::connection::clampToPolicy (const ConnParamSet &req)
Clamp a central-requested parameter set into the accept window.
constexpr ConnParamPolicykleidos::ble::connection::evaluateConnParamPolicy (const ConnParamSet &req)
Evaluate a central-requested parameter set against the policy.
constexpr boolkleidos::ble::connection::liveParamsInPolicy (const LiveConnParams &live)
Whether the live link runs inside the accept window.
constexpr boolkleidos::ble::connection::liveParamsBlockTyping (const LiveConnParams &live)
Whether no keystroke goes out on a link at this timing.
constexpr boolkleidos::ble::connection::liveParamsEndLink (const LiveConnParams &live)
Whether a link still at this timing after every request is ended.
constexpr LinkTimingStepkleidos::ble::connection::linkTimingStep (const LiveConnParams &live, uint8_t requestsMade)
Judge a secured link's live timing after an update (or a refused request).

Variables

constexpr uint8_tkleidos::ble::connection::kCccdInputReportNotifyMask
CCCD bit: input-report notify.
constexpr uint8_tkleidos::ble::connection::kCccdBootInputNotifyMask
CCCD bit: boot keyboard input.
constexpr uint8_tkleidos::ble::connection::kCccdBatteryNotifyMask
CCCD bit: battery level.
constexpr std::size_tkleidos::ble::connection::kCccdMailboxCapacity
How many changes the mailbox holds before the oldest gives way.
constexpr uint16_tkleidos::ble::connection::kAdvFastMinUnits
Fast adv min, 30 ms (0.625 ms units).
constexpr uint16_tkleidos::ble::connection::kAdvFastMaxUnits
Fast adv max, 60 ms (0.625 ms units).
constexpr uint16_tkleidos::ble::connection::kAdvSlowIntervalUnits
Slow adv, 1 s (0.625 ms units).
constexpr uint16_tkleidos::ble::connection::kPreferredIntervalMinUnits
15 ms (1.25 ms units).
constexpr uint16_tkleidos::ble::connection::kPreferredIntervalMaxUnits
30 ms (1.25 ms units).
constexpr uint16_tkleidos::ble::connection::kPreferredLatency
No slave latency while typing.
constexpr uint16_tkleidos::ble::connection::kPreferredTimeoutUnits
4000 ms (10 ms units).
constexpr uint16_tkleidos::ble::connection::kPolicyIntervalMinUnits
7.5 ms floor (1.25 ms units).
constexpr uint16_tkleidos::ble::connection::kPolicyIntervalMaxUnits
75 ms ceiling (1.25 ms units).
constexpr uint16_tkleidos::ble::connection::kPolicyLatencyMax
Max accepted slave latency (events).
constexpr uint16_tkleidos::ble::connection::kPolicyTimeoutMinUnits
1000 ms floor (10 ms units).
constexpr uint16_tkleidos::ble::connection::kPolicyTimeoutMaxUnits
6000 ms ceiling (10 ms units).
constexpr ConnParamSetkleidos::ble::connection::kPreferredParams
The HID-grade parameter set the peripheral actively requests after connect.
constexpr uint8_tkleidos::ble::connection::kPreferredParamsMaxRequests
constexpr uint8_tkleidos::ble::connection::kNoPeerSlot
Sentinel: no bonded slot.
constexpr uint16_tkleidos::ble::connection::kDefaultMtu
ATT default MTU.

Back to the top

Enumeration Type Documentation

ConnParamPolicy #

enum class kleidos::ble::connection::ConnParamPolicy : uint8_t

Outcome of evaluating a central-requested parameter set against the policy.

Enumerator
Accept 

Requested params are fully in-policy; accept as-is.

Renegotiate 

Out of policy but clamp-able; counter with in-policy values.

Reject 

Out of policy and not safely clamp-able; refuse the request.

LinkTimingStep #

enum class kleidos::ble::connection::LinkTimingStep : uint8_t

What the peripheral does with a secured link's timing after an update.

Enumerator
Settled 

In policy: nothing more to ask.

AskAgain 

Out of policy with requests left: ask for the preferred window again.

EndLink 

Out of policy after every request, at a timing no keystroke goes out on.

Keep 

Out of policy after every request, at a timing that still types.

Back to the top

Function Documentation

clampToPolicy() #

ConnParamSet kleidos::ble::connection::clampToPolicy(const ConnParamSet & req)
constexpr

Clamp a central-requested parameter set into the accept window.

Used when evaluateConnParamPolicy returns Renegotiate: the returned tuple is the nearest in-policy counter-offer (intervals clamped into the accept window, latency capped, timeout clamped and then raised if needed to satisfy timeoutCoversLatency).

Parameters
NameDirectionMeaning
reqinCentral-requested parameters (native GAP units).
Returns
An in-policy parameter set closest to req.

evaluateConnParamPolicy() #

ConnParamPolicy kleidos::ble::connection::evaluateConnParamPolicy(const ConnParamSet & req)
constexpr

Evaluate a central-requested parameter set against the policy.

Decision rules:

  • Reject — the request is so far out of policy (e.g. an interval shorter than the spec floor or longer than the typing ceiling) that clamping would change the central's intent unrecognizably; refuse the update outright.
  • Renegotiate — out of policy but safely clamp-able (e.g. a large latency or an over-long timeout); the caller counters with clampToPolicy.
  • Accept — fully inside the accept window and spec-coupling-valid.

Pure logic with no NimBLE dependency so the policy can be unit-tested on host.

Parameters
NameDirectionMeaning
reqinCentral-requested parameters (native GAP units).
Returns
The policy decision for req.

linkTimingStep() #

LinkTimingStep kleidos::ble::connection::linkTimingStep(const LiveConnParams & live, uint8_t requestsMade)
constexpr

Judge a secured link's live timing after an update (or a refused request).

Parameters
NameDirectionMeaning
liveinThe timing the link runs at now.
requestsMadeinPreferred-window requests made on this link so far.
Returns
The step to take.

liveParamsBlockTyping() #

bool kleidos::ble::connection::liveParamsBlockTyping(const LiveConnParams & live)
constexpr

Whether no keystroke goes out on a link at this timing.

Only the slow side: an interval above the typing ceiling, or a supervision timeout above the policy's, at which a keystroke crawls out and a host that vanished mid-burst goes unnoticed for seconds with a key pressed. A short timeout is no reason to hold a keystroke: real hosts connect with one (720 ms is common) and move to the preferred window once asked.

Parameters
NameDirectionMeaning
liveinThe timing the link runs at.
Return values
ValueMeaning
trueRefuse the keystroke.
falseIt may go out.

liveParamsEndLink() #

bool kleidos::ble::connection::liveParamsEndLink(const LiveConnParams & live)
constexpr

Whether a link still at this timing after every request is ended.

Only a link no keystroke may go out on (liveParamsBlockTyping): it is of no use to the owner and holds the device's one link. Every other timing out of policy keeps the link, and it is logged: a supervision timeout below the policy's floor (a host that keeps its 720 ms one, or refuses every request) types promptly, and a latency or a coupling out of policy alone does too. Ending such a link would cut the owner off from that host at every connection.

Parameters
NameDirectionMeaning
liveinThe timing the link runs at.
Return values
ValueMeaning
trueEnd the link.
falseKeep it.

liveParamsInPolicy() #

bool kleidos::ble::connection::liveParamsInPolicy(const LiveConnParams & live)
constexpr

Whether the live link runs inside the accept window.

Parameters
NameDirectionMeaning
liveinThe timing the link runs at.
Return values
ValueMeaning
trueThe interval, latency, timeout and their coupling are in policy.
falseSomething is out of policy.

timeoutCoversLatency() #

bool kleidos::ble::connection::timeoutCoversLatency(uint16_t intervalMaxUnits, uint16_t latency, uint16_t timeoutUnits)
constexpr

Spec coupling check: timeout must outlast (1+latency) connection events.

Per the Bluetooth Core spec the supervision timeout (in ms) must be strictly greater than (1 + latency) * intervalMax (ms) * 2. A central can otherwise pair a long latency with a short timeout to force spurious disconnects.

Parameters
NameDirectionMeaning
intervalMaxUnitsinMax connection interval (1.25 ms units).
latencyinSlave latency (skipped events).
timeoutUnitsinSupervision timeout (10 ms units).
Return values
ValueMeaning
trueThe timeout safely covers the configured latency window.
falseThe (interval, latency, timeout) triple violates the coupling.

Back to the top

Variable Documentation

kPreferredParamsMaxRequests #

uint8_t kleidos::ble::connection::kPreferredParamsMaxRequests
inlineconstexpr

How many times the peripheral asks a central for kPreferredParams on one link: once after its encryption, and again after each update that leaves the link out of policy, up to this count.

Back to the top