Kleidos API Search

In development. It changes without notice.

Topic

Bond Storage

The bonded hosts: their identity, the name the owner gave each, their order, and the removal of one.

  • kleidos::ble::bond::NameStore is the board's table of hosts: one slot for each admitted host, or for a forgotten one whose key is still to be deleted. Each record has a checksum.
  • kleidos::ble::bond::NameStoreTask is the one task that reads and writes the table in NVS, apart from the Bluetooth controller's own use of it.
  • kleidos::ble::bond::BondStore is the one place that changes the table and the stack's keys together: the admission of a host, its removal, and the check, before advertising, that the two agree.

The keys stay in the stack's own storage; here are only identities and names. The table is not opened while the radio is up.

See also
BLE Facade & HID Manager, BLE Connection Management, BLE Types

Files

file src/ble/bond/bond_store.h
Keeps the device's bond table and NimBLE's keystore in step.
file src/ble/bond/host_order.h
The order the owner lists the bonded hosts in.
file src/ble/bond/name_store.h
The device's bond table: one NVS-backed slot per admitted BLE host.
file src/ble/bond/name_store_task.h
Core 0 task that serializes all NameStore NVS access.

Classes

struct kleidos::ble::bond::AdmissionAction
What the main-task drain does with a newly secured link, by its admission. More about kleidos::ble::bond::AdmissionAction
class kleidos::ble::bond::BondStore
Static coordinator that keeps the bond table and NimBLE's keystore in step. More about kleidos::ble::bond::BondStore
class kleidos::ble::bond::NameStore
Static facade over the persisted bond table. More about kleidos::ble::bond::NameStore
class kleidos::ble::bond::NameStoreTask
Static owner of the host-name persistence task. More about kleidos::ble::bond::NameStoreTask

Typedefs

usingkleidos::ble::bond::Host
Bonded-host record alias.

Enumerations

enum class kleidos::ble::bond::IrkRotation : uint8_t { kleidos::ble::bond::IrkRotation::Rotated, kleidos::ble::bond::IrkRotation::NoKeyStored, kleidos::ble::bond::IrkRotation::HostsListed, kleidos::ble::bond::IrkRotation::KeystoreHolds, kleidos::ble::bond::IrkRotation::RadioUp, kleidos::ble::bond::IrkRotation::TableBusy, kleidos::ble::bond::IrkRotation::KeystoreUnread, kleidos::ble::bond::IrkRotation::EraseFailed }
What BondStore::rotateLocalIrkWhenNoHost did with the device's privacy key. More about kleidos::ble::bond::IrkRotation
enum class kleidos::ble::bond::Admission : uint8_t { kleidos::ble::bond::Admission::Known , kleidos::ble::bond::Admission::Admitted , kleidos::ble::bond::Admission::TableFull , kleidos::ble::bond::Admission::Forgotten }
What a newly secured link adds to the bond table (BondStore::admitAuthenticated). More about kleidos::ble::bond::Admission
enum class kleidos::ble::HostMove : uint8_t { kleidos::ble::HostMove::Up , kleidos::ble::HostMove::Down }
Which way a host moves in the owner's list. More about kleidos::ble::HostMove
enum class kleidos::ble::bond::Listing : uint8_t { kleidos::ble::bond::Listing::Unlisted , kleidos::ble::bond::Listing::Listed , kleidos::ble::bond::Listing::Unknown }
What a lock-free read of the bond table says about one identity. More about kleidos::ble::bond::Listing

Functions

constexpr AdmissionActionkleidos::ble::bond::actionFor (Admission admission)
What the drain does with a link BondStore::admitAuthenticated judged.
constexpr boolkleidos::ble::bond::order::listsHost (const NameRecord &record)
Whether a record lists a host (a tombstone and an empty slot do not).
constexpr uint8_tkleidos::ble::bond::order::orderedSlots (const std::array< NameRecord, kMaxBondedHosts > &table, std::array< uint8_t, kMaxBondedHosts > &out)
The listed hosts' slots, in the owner's order.
constexpr boolkleidos::ble::bond::order::move (std::array< uint8_t, kMaxBondedHosts > &slots, uint8_t count, uint8_t slot, HostMove dir)
Move slot one place in an ordered list of slots.
constexpr uint8_tkleidos::ble::bond::order::nextOrder (const std::array< NameRecord, kMaxBondedHosts > &table)
Where a host that joins the table goes: after every listed host.
constexpr uint8_tkleidos::ble::bond::order::placeOf (const std::array< uint8_t, kMaxBondedHosts > &slots, uint8_t count, uint8_t slot)
Where the host in slot sits in the owner's list.

Variables

constexpr uint8_tkleidos::ble::bond::kMaxHosts
Bond-table capacity.
constexpr uint8_tkleidos::ble::bond::kNoSlot
Sentinel for "no matching bond slot".
constexpr uint8_tkleidos::ble::bond::kNimbleStoreCapacity
NimBLE keystore capacity — MUST mirror CONFIG_BT_NIMBLE_MAX_BONDS.
constexpr uint8_tkleidos::ble::bond::order::kNoSlot
A slot no host holds, as returned by a lookup that found nothing.

Back to the top

Enumeration Type Documentation

Admission #

enum class kleidos::ble::bond::Admission : uint8_t

What a newly secured link adds to the bond table (BondStore::admitAuthenticated).

Enumerator
Known 

The host was already listed; its last-seen time was refreshed.

Admitted 

A new host took a free slot.

TableFull 

No slot is free: the caller arms the replace-oldest prompt.

Forgotten 

The host was forgotten and reconnected on its old key: not admitted.

HostMove #

enum class kleidos::ble::HostMove : uint8_t

Which way a host moves in the owner's list.

Enumerator
Up 

One place towards the top.

Down 

One place towards the bottom.

IrkRotation #

enum class kleidos::ble::bond::IrkRotation : uint8_t

What BondStore::rotateLocalIrkWhenNoHost did with the device's privacy key.

Enumerator
Rotated 

No host left: the key is erased, the next start makes a new one.

NoKeyStored 

No host left and no key stored: the next start makes one anyway.

HostsListed 

A host is still listed and keeps resolving the device: key kept.

KeystoreHolds 

The table lists none, but the keystore holds a confirmed host's key the next host sync lists again: key kept.

RadioUp 

The host runs and holds the key in RAM: key kept.

TableBusy 

The table could not be read: key kept (never a guess).

KeystoreUnread 

The persisted keystore could not be read: key kept.

EraseFailed 

The key's records could not be erased: key kept.

Listing #

enum class kleidos::ble::bond::Listing : uint8_t

What a lock-free read of the bond table says about one identity.

Enumerator
Unlisted 

No active slot holds the identity.

Listed 

An active slot holds it.

Unknown 

The table was not published yet this boot: nothing to say.

Back to the top

Function Documentation

actionFor() #

AdmissionAction kleidos::ble::bond::actionFor(Admission admission)
nodiscardconstexpr

What the drain does with a link BondStore::admitAuthenticated judged.

A forgotten host that came back on its old key is dropped and never reads as a host: its link would otherwise stay authenticated whenever the delete of that key failed again, and a send could type to a laptop the owner removed (finding C9).

Parameters
NameDirectionMeaning
admissioninThe verdict.
Returns
Whether the link stays and whether the replace-oldest prompt arms.

listsHost() #

bool kleidos::ble::bond::order::listsHost(const NameRecord & record)
constexpr

Whether a record lists a host (a tombstone and an empty slot do not).

Parameters
NameDirectionMeaning
recordinA bond-table record.
Returns
true for an active host.

move() #

bool kleidos::ble::bond::order::move(std::array< uint8_t, kMaxBondedHosts > & slots, uint8_t count, uint8_t slot, HostMove dir)
constexpr

Move slot one place in an ordered list of slots.

Parameters
NameDirectionMeaning
slotsin, outThe slots in order, as orderedSlots wrote them.
countinHow many of slots are listed.
slotinThe host to move.
dirinWhich way.
Return values
ValueMeaning
trueThe host moved.
falseIt is already at that edge, or slot is not listed.

nextOrder() #

uint8_t kleidos::ble::bond::order::nextOrder(const std::array< NameRecord, kMaxBondedHosts > & table)
constexpr

Where a host that joins the table goes: after every listed host.

Parameters
NameDirectionMeaning
tableinThe bond table, every slot.
Returns
One past the largest position a listed host holds, or 0 on an empty table.

orderedSlots() #

uint8_t kleidos::ble::bond::order::orderedSlots(const std::array< NameRecord, kMaxBondedHosts > & table, std::array< uint8_t, kMaxBondedHosts > & out)
constexpr

The listed hosts' slots, in the owner's order.

Sorted by (order, slot): hosts that share a position (a table written before the order existed, or a gap a delete left) keep their slot order.

Parameters
NameDirectionMeaning
tableinThe bond table, every slot.
outoutThe slots in order; entries past the count are kNoSlot.
Returns
How many hosts are listed.

placeOf() #

uint8_t kleidos::ble::bond::order::placeOf(const std::array< uint8_t, kMaxBondedHosts > & slots, uint8_t count, uint8_t slot)
constexpr

Where the host in slot sits in the owner's list.

Parameters
NameDirectionMeaning
slotsinThe slots in order.
countinHow many are listed.
slotinThe host.
Returns
Its 0-based place, or kNoSlot when it is not listed.

Back to the top

Variable Documentation

kNimbleStoreCapacity #

uint8_t kleidos::ble::bond::kNimbleStoreCapacity
inlineconstexpr

NimBLE keystore capacity — MUST mirror CONFIG_BT_NIMBLE_MAX_BONDS.

One slot of HEADROOM over the app host limit (kMaxHosts). Without it a fresh (kMaxHosts+1)-th pairing overflows NimBLE's store, and its default round-robin store_status_cb (ble_store_util_status_rr) silently evicts the oldest legitimate bond BEFORE the app's deny-by-default eviction prompt can run. With the headroom the candidate persists in the spare slot, the app's drain finds no free slot and arms the prompt, and the oldest bond is evicted only on explicit approval. The spare slot is transient headroom for a pending candidate, NOT a (kMaxHosts+1)-th usable host — the user-visible host limit stays kMaxHosts. A static assertion of the device build binds this to MYNEWT_VAL(BLE_STORE_MAX_BONDS), so the build configuration and this constant cannot differ.

Back to the top