Kleidos API Search

In development. It changes without notice.

Topic

BLE Types

The values every part of Bluetooth speaks: the keyboard layouts, the commands and events, the state of a session and of the stack, and the record of a host.

There are seven keyboard layouts: US, Spanish, UK, French, German, Portuguese and Italian (kleidos::ble::KbLayout). A command goes from the screen's core to the stack's, an event comes back, and each is one typed envelope.

See also
BLE Facade & HID Manager, Bond Storage, BLE Stack Integration

Files

file src/ble/types/ble_commands.h
POD command envelope posted from FSM/UI/web to the BLE stack task.
file src/ble/types/ble_events.h
POD event payloads published by the BLE stack task to subscribers.
file src/ble/types/keyboard_layouts.h
Per-layout ASCII-to-HID-scancode tables for BLE HID typing.
file src/ble/types/name_record.h
Stable on-flash record for the BLE host-name store.
file src/ble/types/session_state.h
The HID session's runtime state and the rules every layer reads it by.
file src/ble/types/stack_state.h
The BLE stack's public lifecycle state, as the screens read it.

Namespaces

namespace kleidos::ble::session
The rules the session state is read by: its public state, whether it takes a burst, and the state a burst leaves it in.

Classes

struct kleidos::ble::BleCommand
Typed command envelope posted to BleCommandQueue (≤ 64 B by contract). More about kleidos::ble::BleCommand
struct kleidos::ble::BleEvent
Typed event envelope published on ble::stack::BleEventBus. More about kleidos::ble::BleEvent
struct kleidos::LayoutEntry
One ASCII glyph expressed as a HID scancode plus modifier flags. More about kleidos::LayoutEntry
struct kleidos::ble::NameRecord
Packed 44-byte persisted host-name record. More about kleidos::ble::NameRecord
struct kleidos::ble::session::WaitBudget
How long an advertising session waits for a host. More about kleidos::ble::session::WaitBudget

Typedefs

usingkleidos::ble::EventHandler
Subscriber callback for BleEvent values (heap-free, fixed size), the argument of kleidos::ble::Facade::subscribe(EventHandler).
usingkleidos::ble::SubscriptionId
Event-subscription handle; 0 = invalid.

Enumerations

enum class kleidos::ble::CommandKind : uint8_t { kleidos::ble::CommandKind::Start, kleidos::ble::CommandKind::Stop, kleidos::ble::CommandKind::AcceptNc, kleidos::ble::CommandKind::RejectNc, kleidos::ble::CommandKind::BeginTyping, kleidos::ble::CommandKind::CancelTyping, kleidos::ble::CommandKind::SetTargetHost, kleidos::ble::CommandKind::RemoveBond, kleidos::ble::CommandKind::RenameBond, kleidos::ble::CommandKind::ResolveEviction, kleidos::ble::CommandKind::ApproveRepair, kleidos::ble::CommandKind::Settle }
enum class kleidos::ble::EventKind : uint8_t { kleidos::ble::EventKind::StateChanged, kleidos::ble::EventKind::Connected, kleidos::ble::EventKind::Disconnected, kleidos::ble::EventKind::AuthRequired, kleidos::ble::EventKind::AuthCompleted, kleidos::ble::EventKind::AuthFailed, kleidos::ble::EventKind::BondAdded, kleidos::ble::EventKind::BondRemoved, kleidos::ble::EventKind::NumericCmpRequested, kleidos::ble::EventKind::NumericCmpResolved, kleidos::ble::EventKind::RepairRequested, kleidos::ble::EventKind::BondEvictionRequested, kleidos::ble::EventKind::TypingStarted, kleidos::ble::EventKind::TypingFinished, kleidos::ble::EventKind::TypingFailed, kleidos::ble::EventKind::MtuChanged, kleidos::ble::EventKind::RssiSampled, kleidos::ble::EventKind::CccdChanged }
enum class kleidos::ble::TypingEventStatus : uint8_t { kleidos::ble::TypingEventStatus::Success, kleidos::ble::TypingEventStatus::Disconnected, kleidos::ble::TypingEventStatus::NotConnected, kleidos::ble::TypingEventStatus::Cancelled, kleidos::ble::TypingEventStatus::Timeout, kleidos::ble::TypingEventStatus::Unsupported, kleidos::ble::TypingEventStatus::Error }
enum class kleidos::ble::UnstoredPairing : uint8_t { kleidos::ble::UnstoredPairing::None, kleidos::ble::UnstoredPairing::NoRoom, kleidos::ble::UnstoredPairing::StoreError, kleidos::ble::UnstoredPairing::IdentityTaken, kleidos::ble::UnstoredPairing::IdentityUnproven }
enum class kleidos::KbLayout : uint8_t { kleidos::KbLayout::US, kleidos::KbLayout::ES, kleidos::KbLayout::UK, kleidos::KbLayout::FR, kleidos::KbLayout::DE, kleidos::KbLayout::PT, kleidos::KbLayout::IT }
enum class kleidos::BleState : uint8_t { kleidos::BleState::OFF, kleidos::BleState::ADVERTISING, kleidos::BleState::CONNECTED, kleidos::BleState::TYPING, kleidos::BleState::ERROR }
enum class kleidos::BleTypingResult : uint8_t { kleidos::BleTypingResult::SUCCESS, kleidos::BleTypingResult::NotConnected, kleidos::BleTypingResult::DISCONNECTED, kleidos::BleTypingResult::ERROR, kleidos::BleTypingResult::CapsLockOn }
Terminal result returned by the synchronous typing helpers. More about kleidos::BleTypingResult
enum class kleidos::ble::session::HostAsk : uint8_t { kleidos::ble::session::HostAsk::None , kleidos::ble::session::HostAsk::RepairPrompt , kleidos::ble::session::HostAsk::Reconnect , kleidos::ble::session::HostAsk::Pairing }
What an advertising session waits on once a host has asked something of it. More about kleidos::ble::session::HostAsk
enum class kleidos::ble::session::AskWindow : uint8_t { kleidos::ble::session::AskWindow::None , kleidos::ble::session::AskWindow::Link , kleidos::ble::session::AskWindow::Reconnect }
The window an ask of the session is judged on. More about kleidos::ble::session::AskWindow
enum class kleidos::ble::StackState : uint8_t { kleidos::ble::StackState::OFF, kleidos::ble::StackState::STARTING, kleidos::ble::StackState::ADVERTISING, kleidos::ble::StackState::AUTHENTICATING, kleidos::ble::StackState::CONNECTED, kleidos::ble::StackState::TYPING, kleidos::ble::StackState::STOPPING, kleidos::ble::StackState::ERROR }

Functions

constexpr StackStatekleidos::ble::session::publicState (BleState s, bool pairing)
The state the screens are told the session is in.
constexpr boolkleidos::ble::session::acceptsBurst (BleState s)
Whether a new burst of key reports may start in s.
constexpr BleStatekleidos::ble::session::afterBurst (BleTypingResult r)
The state a burst that ended with r leaves the session in.
constexpr boolkleidos::ble::session::advertisesAfterLink (BleState s)
Whether the radio advertises in s once a link has ended.
constexpr HostAskkleidos::ble::session::hostAsk (bool repairPrompted, bool reconnecting, bool pairing)
What an advertising session waits on, from what the link reads now.
constexpr boolkleidos::ble::session::askWindowStarts (HostAsk was, HostAsk now)
Whether the window of what the session waits on starts on this poll.
constexpr AskWindowkleidos::ble::session::askWindow (HostAsk ask)
The window an ask is judged on.
constexpr boolkleidos::ble::session::repairEndsWithLink (bool approved, bool askingHostPaired)
Whether an authenticated link ends an allowed re-pair.
constexpr boolkleidos::ble::session::hostWaitLapsed (const WaitBudget &budget, uint32_t advertisingMs, std::optional< uint32_t > pairingMs)
Whether an advertising session has waited for a host as long as it may.

Variables

constexpr uint8_tkleidos::kKbLayoutCount
const std::array< LayoutEntry, 128 >kleidos::kLayoutEs
Spanish (Spain) table.
const std::array< LayoutEntry, 128 >kleidos::kLayoutUk
United Kingdom table.
const std::array< LayoutEntry, 128 >kleidos::kLayoutFr
French (France) table.
const std::array< LayoutEntry, 128 >kleidos::kLayoutDe
German (Germany) table.
const std::array< LayoutEntry, 128 >kleidos::kLayoutPt
Portuguese table.
const std::array< LayoutEntry, 128 >kleidos::kLayoutIt
Italian table.
constexpr uint8_tkleidos::ble::kMaxBondedHosts
Bond-table capacity.
constexpr uint8_tkleidos::ble::kNameRecordVersion
Current on-flash record version.
constexpr uint8_tkleidos::ble::kNameRecordActiveFlag
constexpr uint8_tkleidos::ble::kNameRecordPendingUnpairFlag
constexpr uint16_tkleidos::ble::kNameMaxBytes
Host-name buffer size (incl. NUL).

Back to the top

Typedef Documentation

EventHandler #

using kleidos::ble::EventHandler

Subscriber callback for BleEvent values (heap-free, fixed size), the argument of kleidos::ble::Facade::subscribe(EventHandler).

Shared by kleidos::ble::Facade::subscribe() and kleidos::ble::stack::BleEventBus so the two never double-wrap. The 32-byte inline capacity fits a small capturing lambda; a larger target is a compile error (bump the capacity here).

SubscriptionId #

using kleidos::ble::SubscriptionId

Event-subscription handle; 0 = invalid.

Shared by kleidos::ble::Facade::subscribe() and kleidos::ble::stack::BleEventBus, as kleidos::ble::EventHandler is.

Back to the top

Enumeration Type Documentation

AskWindow #

enum class kleidos::ble::session::AskWindow : uint8_t

The window an ask of the session is judged on.

Enumerator
None 

Nothing asked: the host window runs.

Link 

What the live link asks (a re-pair prompt, a comparison): a new ask restarts it.

Reconnect 

The return of the host the owner allowed: armed once, kept until the approval ends.

BleState #

enum class kleidos::BleState : uint8_t

Observable lifecycle state of the NimBLE HID session.

State Entered from Trigger Exits to
OFF (initial) Boot, full deinit ADVERTISING
ADVERTISING OFF begin() / disconnect CONNECTED, ERROR
CONNECTED ADVERTISING / TYPING Host paired + authenticated, or a burst landed TYPING, ADVERTISING
TYPING CONNECTED typeCredential() CONNECTED, ERROR
ERROR ADVERTISING / TYPING Init / connection / link error OFF (via end())

A host that is pairing keeps the session in ADVERTISING (the screens read it as AUTHENTICATING, kleidos::ble::session::publicState).

A burst that lands leaves the link as it found it, ready for the next one: the 2FA code the device offers after the login is a second burst of the same session.

Enumerator
OFF 

BLE not initialized.

ADVERTISING 

Waiting for a host connection.

CONNECTED 

Paired and ready to type.

TYPING 

Actively sending keystrokes.

ERROR 

Initialization or connection failed.

BleTypingResult #

enum class kleidos::BleTypingResult : uint8_t

Terminal result returned by the synchronous typing helpers.

Enumerator
SUCCESS 

Password typed successfully.

NotConnected 

Host never connected within timeout.

DISCONNECTED 

Host disconnected mid-typing.

ERROR 

BLE init failed.

CapsLockOn 

The host's Caps Lock stayed on (or came on): no ENTER went out.

CommandKind #

enum class kleidos::ble::CommandKind : uint8_t

Discriminator for the BleCommand union payload.

Enumerator
Start 

Begin advertising in the requested StartMode.

Stop 

Tear the radio down gracefully.

AcceptNc 

Accept the Numeric Comparison request u.nc names, if still pending.

RejectNc 

Reject the Numeric Comparison request u.nc names, if still pending.

BeginTyping 

Type a staged credential/password.

CancelTyping 

Abort the in-flight typing operation.

SetTargetHost 

Select the active bonded host slot.

RemoveBond 

Remove a bonded host by slot.

RenameBond 

Rename a bonded host by slot.

ResolveEviction 

Resolve the full-table bond-eviction prompt.

ApproveRepair 

Delete the re-pairing host's bond and drop its link (an Allow).

Settle 

Run nothing; acknowledged once the state is published.

EventKind #

enum class kleidos::ble::EventKind : uint8_t

Discriminator for the BleEvent union payload.

Enumerator
StateChanged 

Stack state transition (state arm).

Connected 

Peer link established (conn arm).

Disconnected 

Peer link dropped (disc arm).

AuthRequired 

Pairing/authentication started.

AuthCompleted 

Pairing/authentication succeeded.

AuthFailed 

Pairing/authentication failed.

BondAdded 

A bonded host was stored (bond arm).

BondRemoved 

A bonded host was removed (bond arm).

NumericCmpRequested 

Numeric Comparison prompt armed (nc arm).

NumericCmpResolved 

Numeric Comparison prompt resolved.

RepairRequested 

Re-pair confirmation prompt armed (a bonded host is re-pairing).

BondEvictionRequested 

Bond table full — replace-oldest confirmation prompt armed.

TypingStarted 

Typing began (typ arm).

TypingFinished 

Typing finished (typ arm).

TypingFailed 

Typing aborted with an error (typ arm).

MtuChanged 

Negotiated MTU updated (mtu arm).

RssiSampled 

New RSSI sample (rssi arm).

CccdChanged 

Client CCCD subscription changed (cccd arm).

HostAsk #

enum class kleidos::ble::session::HostAsk : uint8_t

What an advertising session waits on once a host has asked something of it.

Enumerator
None 

Nothing asked yet: the host window runs.

RepairPrompt 

A bonded host asked to pair again; the owner's answer is awaited.

Reconnect 

Allowed: the old bond and the link went; the host's return is awaited.

Pairing 

A pairing is under way: a comparison raised on the live link.

KbLayout #

enum class kleidos::KbLayout : uint8_t

Keyboard layout identifier; stored in NVS and used to select HID scancode tables.

Enumerator
US 

US English (built-in printable-ASCII fallback).

ES 

Spanish (Spain).

UK 

United Kingdom.

FR 

French (France).

DE 

German (Germany).

PT 

Portuguese.

IT 

Italian.

StackState #

enum class kleidos::ble::StackState : uint8_t

Observable lifecycle state of the BLE stack.

The table below documents the public transitions published by ble::stack::BleStackTask via ble::stack::BleEventBus. Terminal ERROR transitions clear the radio through stop() before the next start() may be issued.

From Allowed next states Trigger
OFF STARTING Facade::start() accepted
STARTING ADVERTISING, ERROR NimBLE init success / failure
ADVERTISING AUTHENTICATING, CONNECTED, ERROR NC raised / bonded host reconnects / timeout
AUTHENTICATING CONNECTED, ADVERTISING, ERROR Keys land / NC refused, pairing failed, host left / timeout
CONNECTED TYPING, ADVERTISING, OFF Credential selected / link drop
TYPING CONNECTED, OFF, ERROR Reports flushed / link drop
STOPPING OFF nimble_port_deinit() done
ERROR STARTING Facade::start() retry
Enumerator
OFF 

Radio down, fully deinitialized.

STARTING 

Bring-up in progress.

ADVERTISING 

Waiting for a peer to connect.

AUTHENTICATING 

A host is pairing: from its numeric comparison until its keys land.

CONNECTED 

Paired and ready to type.

TYPING 

Sending HID reports.

STOPPING 

Graceful teardown in progress.

ERROR 

Initialization or link failure.

TypingEventStatus #

enum class kleidos::ble::TypingEventStatus : uint8_t

Status code packed inside TypingFinished / TypingFailed events.

Enumerator
Success 

Credential typed without error.

Disconnected 

Host disconnected mid-typing.

NotConnected 

Link was not connected at start.

Cancelled 

Caller cancelled the operation.

Timeout 

Host stopped acknowledging reports.

Unsupported 

Codepoint not typeable on the active layout.

Error 

Generic failure.

UnstoredPairing #

enum class kleidos::ble::UnstoredPairing : uint8_t

What a pairing the owner confirmed left when the keystore did not keep its keys (Facade::takeUnstoredPairing).

Enumerator
None 

No such pairing since the last read.

NoRoom 

The keystore was out of room: no host was added.

StoreError 

The keystore failed to store its keys, or refused an identity no host can have: no host was added.

IdentityTaken 

It distributed the identity of a host already saved: refused, and the saved host keeps its key, label, place and target.

IdentityUnproven 

It claimed the host whose re-pair the owner allowed without the identity key that host's bond held: refused (a host whose key changed pairs again from the add-host page).

Back to the top

Function Documentation

acceptsBurst() #

bool kleidos::ble::session::acceptsBurst(BleState s)
constexpr

Whether a new burst of key reports may start in s.

The link must also be up and authenticated; this is the state's half of that rule.

Parameters
NameDirectionMeaning
sinRuntime session state.
Return values
ValueMeaning
trueA burst may start.
falseThe session is not ready for one.

advertisesAfterLink() #

bool kleidos::ble::session::advertisesAfterLink(BleState s)
constexpr

Whether the radio advertises in s once a link has ended.

A failed session (ERROR) is quiet: no host can reach it until its owner, who reads the failure, stops the stack or advertises again on purpose (BleHidManager::rearmAdvertising). A stack that is down (OFF) has no advertising to resume. Every other state takes the next host.

Parameters
NameDirectionMeaning
sinRuntime session state.
Return values
ValueMeaning
trueAdvertising resumes after the link ends.
falseThe radio stays quiet.

afterBurst() #

BleState kleidos::ble::session::afterBurst(BleTypingResult r)
constexpr

The state a burst that ended with r leaves the session in.

Parameters
NameDirectionMeaning
rinHow the burst ended.
Returns
The runtime state to store.

askWindow() #

AskWindow kleidos::ble::session::askWindow(HostAsk ask)
constexpr

The window an ask is judged on.

A re-pair prompt and a comparison are asked by the live link, and each new one gets the link's window afresh. The return of the host whose re-pair the owner allowed is that host's: its window is armed from the first poll after the Allow and kept until the approval ends (that host's fresh pairing, the session's end, the hard stop), so another host's link or comparison in between neither closes nor restarts it.

Parameters
NameDirectionMeaning
askinWhat the session waits on.
Returns
Its window.

askWindowStarts() #

bool kleidos::ble::session::askWindowStarts(HostAsk was, HostAsk now)
constexpr

Whether the window of what the session waits on starts on this poll.

Parameters
NameDirectionMeaning
wasinWhat the session waited on at the previous poll.
nowinWhat it waits on now.
Return values
ValueMeaning
trueA new ask began: the first poll of a prompt, of the reconnect an Allow awaits, or of a pairing.
falseNothing is asked, or the same ask goes on.

hostAsk() #

HostAsk kleidos::ble::session::hostAsk(bool repairPrompted, bool reconnecting, bool pairing)
constexpr

What an advertising session waits on, from what the link reads now.

A bonded host that asks to pair again is refused until the owner answers the re-pair prompt, and keeps its link up meanwhile: the prompt is a pairing under way as much as the comparison is, and waits on a window of its own, not on what the host window has left. An Allow deletes the host's old bond and drops its link, and the session waits for the host to come back, on a window of its own again; the fresh pairing it starts then (its comparison) runs on a third. Each starts when the session reads it, and the hard stop bounds them all.

Parameters
NameDirectionMeaning
repairPromptedinA re-pair prompt is armed for the live link.
reconnectinginThe owner allowed a re-pair whose fresh pairing has not completed yet.
pairinginThe link reads as pairing.
Returns
What the session waits on.

hostWaitLapsed() #

bool kleidos::ble::session::hostWaitLapsed(const WaitBudget & budget, uint32_t advertisingMs, std::optional< uint32_t > pairingMs)
constexpr

Whether an advertising session has waited for a host as long as it may.

Parameters
NameDirectionMeaning
budgetinThe session's windows.
advertisingMsinTime since advertising started.
pairingMsinTime since the session first read the link as pairing; empty while no pairing is under way.
Return values
ValueMeaning
trueThe wait is over: past the hard stop, past the pairing's own window, or, with no pairing under way, past the host window.
falseThe session keeps waiting.

publicState() #

StackState kleidos::ble::session::publicState(BleState s, bool pairing)
constexpr

The state the screens are told the session is in.

The session waits in ADVERTISING until a host's link authenticates. A host that is pairing is already on the link by then, and from the numeric comparison it raised until its keys land the screens are told AUTHENTICATING: the owner has been asked about that host, and once the owner says yes the device waits on the host's own confirmation. A host that reconnects with a bond it already holds raises no comparison, so its link goes from ADVERTISING straight to CONNECTED.

Parameters
NameDirectionMeaning
sinRuntime session state.
pairinginA pairing the owner was asked about is under way on the live link: a comparison raised on it, or a re-pair the owner allowed, and the link has not authenticated, failed or been refused since.
Returns
Its public StackState.

repairEndsWithLink() #

bool kleidos::ble::session::repairEndsWithLink(bool approved, bool askingHostPaired)
constexpr

Whether an authenticated link ends an allowed re-pair.

The approval, the pairing window it opened and its reconnect window belong to the host that asked: only that host's fresh pairing ends them on a link. A different host connecting, bonded or pairing new, leaves them as they are; the session's end and the hard stop end them whatever links came.

Parameters
NameDirectionMeaning
approvedinThe owner allowed a re-pair still awaited.
askingHostPairedinThe link paired fresh (a comparison on it), and its identity is the one that asked.
Returns
true when the approval is spent.

Back to the top

Variable Documentation

kKbLayoutCount #

uint8_t kleidos::kKbLayoutCount
inlineconstexpr

Number of KbLayout values. Every layout is below it, so a stored byte at or past it names no layout.

kNameRecordActiveFlag #

uint8_t kleidos::ble::kNameRecordActiveFlag
inlineconstexpr

flags bit marking an active slot.

kNameRecordPendingUnpairFlag #

uint8_t kleidos::ble::kNameRecordPendingUnpairFlag
inlineconstexpr

flags bit marking a forgotten-but-not-yet-unpaired tombstone. The record keeps the identity address so the deferred NimBLE keystore deletion can run at the next host start-up; the slot is inactive (no kNameRecordActiveFlag) so it never appears as a bonded host.

Back to the top