In development. It changes without notice.
Topic
BLE Stack Integration
The owner of NimBLE on core 0: the stack's task, the queue of commands to it and the bus of events from it.
- kleidos::
ble:: stack:: BleStackTask starts and stops NimBLE, drains the commands and publishes the events. It is created once, after its queue and its bus, and lives as long as the firmware runs. - kleidos::
ble:: stack:: BleCommandQueue takes the commands of any task, in a fixed array. - kleidos::
ble:: stack:: BleEventBus gives each event to up to eight subscribers; a subscription that ended cannot end another by mistake.
The host tests run none of this: they use a stand-in for the stack.
Files | |
| file | src/ |
| Whether the stack may resume advertising on its own. | |
| file | src/ |
| When a change of the pairing window may restart the running advertising set. | |
| file | src/ |
| MPSC typed command queue from FSM/UI/web to the BLE stack task. | |
| file | src/ |
| MPMC publish/ | |
| file | src/ |
| Core 0 task that owns the NimBLE stack and drains BLE commands. | |
| file | src/ |
| How long the NimBLE host task spends in Kleidos' own callbacks. | |
| file | src/ |
| How the debug console's guard reads encode a timing judge and a keystore refusal. | |
| file | src/ |
| Admits a call into the NimBLE host only while the host's memory exists. | |
| file | src/ |
NimBLE host adapter (concrete NimBleHostPort) + free-function shim. | |
| file | src/ |
| Vendor-free port (hexagonal seam) isolating the BLE host stack. | |
| file | src/ |
The raw Apache NimBLE C-API implementation of kleidos::, the one host port on the device. | |
| file | src/ |
The NimBLE-free host:: call surface, forwarding each call to the active host port (device and native builds). | |
| file | src/ |
| A fixed-size count of events by reason code, for bench diagnostics. | |
| file | src/ |
| How long each part of a BLE teardown may take, and their sum. | |
Typedefs | |
| using | kleidos:: |
| Subscriber callback (shared with Facade). | |
| using | kleidos:: |
| Subscription handle (shared with Facade). | |
Functions | |
| constexpr AdvFilter | kleidos:: |
| The filter the window asks of the advertising set. | |
| constexpr WindowRestart | kleidos:: |
| Whether a change of the pairing window restarts the running set. | |
| constexpr bool | kleidos:: |
| Whether the owner's start may start an advertising set now. | |
| constexpr uint8_t | kleidos:: |
| The judge code of a timing step. | |
| constexpr uint64_t | kleidos:: |
| Pack a timing judge into one word. | |
| constexpr JudgedTiming | kleidos:: |
| Unpack a word packJudgedTiming made. | |
| constexpr size_t | kleidos:: |
| The count slot of a keystore verdict. | |
| constexpr bool | kleidos:: |
| Pure decision: whether a call may enter the host. | |
| bool | kleidos:: |
| Initialize NimBLE, build the HID service, start advertising. | |
| void | kleidos:: |
| Stop advertising, disconnect any peer (waits up to 1500 ms), then fully deinitialize the host stack. Resets all link-state. | |
| void | kleidos:: |
| Cancel any in-flight shutdown attempt (called at start). | |
| bool | kleidos:: |
| True once NimBLE has been initialized. | |
| bool | kleidos:: |
True once the host+controller have synced (the onSync callback ran). | |
| bool | kleidos:: |
| True when a peer connection is up (link layer). | |
| bool | kleidos:: |
| True when the link is encrypted and MITM-authenticated. | |
| bool | kleidos:: |
| True while a pairing is under way on the live link. | |
| bool | kleidos:: |
| True while a full teardown is in progress. | |
| bool | kleidos:: |
| True while the host is actively advertising. | |
| bool | kleidos:: |
| Delete a runtime NimBLE bond by identity address. | |
| bool | kleidos:: |
| Delete a runtime NimBLE bond using a public-address fallback. | |
| bool | kleidos:: |
| Read every NimBLE-persisted bond in one pass, or say it could not. | |
| bool | kleidos:: |
Read the bonds the keystore persisted, with the radio fully off (NimBleHostPort::). | |
| StoreSweep | kleidos:: |
Delete every stored record no whole bond owns (NimBleHostPort::). | |
| void | kleidos:: |
Drop the live link when its peer is addr (NimBleHostPort::). | |
| uint8_t | kleidos:: |
| Count the bonds NimBLE persisted in NVS, readable while the radio is OFF. | |
| bool | kleidos:: |
| Inject the user's Numeric Comparison decision into the link that asked. | |
| bool | kleidos:: |
True when a yes to a comparison raised on connHandle may confirm it. | |
| void | kleidos:: |
| Start (or restart) advertising. | |
| void | kleidos:: |
| Stop a failed session: its advertising, and its link if it never secured. | |
| void | kleidos:: |
| Open or close the "add a new host" pairing window. | |
| bool | kleidos:: |
| True while the "add a new host" pairing window is open. | |
| bool | kleidos:: |
| The identity of the bonded host that raised the re-pair prompt. | |
| bool | kleidos:: |
| Keep the identity key of the host whose re-pair the owner allowed, before its old bond is deleted. | |
| void | kleidos:: |
| Drop the link of the host whose re-pair the owner allowed. | |
| bool | kleidos:: |
| Whether the live link is the allowed host's fresh pairing. | |
| void | kleidos:: |
| The allowed host's fresh pairing completed: forget its identity. | |
| bool | kleidos:: |
| Whether the advertising is refused because privacy could not be set up. | |
| void | kleidos:: |
| Apply any connection parameter update requested by the callbacks. Runs on BleStackTask/ | |
| void | kleidos:: |
| Apply any MTU update requested by the callbacks. Runs on BleStackTask/ | |
| void | kleidos:: |
| Set the battery level the Battery Level characteristic serves. | |
| void | kleidos:: |
| Notify a subscribed host of a battery level it does not have yet. Runs on BleStackTask/ | |
| bool | kleidos:: |
| Send an 8-byte HID keyboard report. | |
| bool | kleidos:: |
| Send one all-zero keyboard report, so the host holds no key. | |
| uint8_t | kleidos:: |
| The keyboard LED byte the host last wrote on the live link. | |
| uint32_t | kleidos:: |
| How many keyboard LED writes the host has made, on any link. | |
| bool | kleidos:: |
Atomically read-and-clear the connect pending flag. When it returns true, addrOut, addrTypeOut, and mtuOut describe the peer from the onConnect callback. | |
| bool | kleidos:: |
Atomically read-and-clear the auth-complete pending flag. When it returns true, addrOut is filled with the peer address that just authenticated. | |
| bool | kleidos:: |
| Atomically read-and-clear a confirmed pairing the keystore did not keep. | |
| bool | kleidos:: |
| Atomically read-and-clear the disconnect pending flag. | |
| bool | kleidos:: |
| Take the oldest CCCD change the subscribe callback parked. | |
| void | kleidos:: |
| Wipe every pending mailbox: the flags and the CCCD changes (called at stopRuntime entry). | |
| uint32_t | kleidos:: |
| Worst-case NimBLE callback wall time. | |
| uint32_t | kleidos:: |
| Number of callbacks that exceeded their budget. | |
| uint32_t | kleidos:: |
| Worst-case keystore write wall time (NimBLE's NVS persistence of a bond). | |
| uint32_t | kleidos:: |
| Number of keystore write callbacks timed. | |
| uint32_t | kleidos:: |
| CCCD changes that gave way to a newer one in a full mailbox. | |
| size_t | kleidos:: |
Render a security trace into out. | |
| void | kleidos:: |
Fill out with a cheap snapshot of the live host link. | |
| uint32_t | kleidos:: |
| Total HID keystroke reports successfully sent since boot. | |
| uint32_t | kleidos:: |
| Teardowns that freed the host with a caller from another task still inside it, the drain before the free having run out (since boot). | |
| uint8_t | kleidos:: |
| Currently selected HOGP Protocol Mode. | |
| void | kleidos:: |
Native-only: inject the NimBleHostPort the host:: shim forwards to. | |
Variables | |
| constexpr uint32_t | kleidos:: |
| constexpr std::array< connection:: | kleidos:: |
| constexpr std::array< security:: | kleidos:: |
| constexpr size_t | kleidos:: |
| The slot that counts bound records refused for want of a confirmed key (unbound). | |
| constexpr size_t | kleidos:: |
| Count slots the gate keeps: one per refused verdict, then the unbound one. | |
| constexpr size_t | kleidos:: |
| What gateRefusalSlot returns for a verdict the gate does not refuse. | |
| constexpr size_t | kleidos:: |
Distinct reason codes a tally keeps before it folds the rest into other. | |
| constexpr uint32_t | kleidos:: |
| constexpr uint32_t | kleidos:: |
| constexpr uint32_t | kleidos:: |
| constexpr uint32_t | kleidos:: |
| constexpr uint32_t | kleidos:: |
| constexpr uint32_t | kleidos:: |
| The longest a teardown takes, end to end. | |
Enumeration Type Documentation
AdvFilter #
HostCaller #
HostNeed #
HostPhase #
Where the NimBLE host stands in one radio session.
WindowRestart #
What a change of the pairing window does to the running advertising set.
Function Documentation
advFilterFor() #
The filter the window asks of the advertising set.
- Parameters
-
Name Direction Meaning windowOpen in The "add a new host" pairing window is open. acceptListUsable in The build filters by the controller accept-list (an ESP32-S3; not the classic ESP32's host-based privacy). anyBonded in The keystore lists at least one bonded host.
- Returns
AdvFilter::with the window closed, a usable list and a bonded host;AcceptList AdvFilter::otherwise.Open
callbackMaxUs() #
Worst-case NimBLE callback wall time.
The GAP event, attribute access and keystore status callbacks; the keystore write is storeWriteMaxUs().
- Returns
- Max callback time in microseconds since boot.
callbackOverBudgetCount() #
Number of callbacks that exceeded their budget.
The same callbacks as callbackMaxUs(), the keystore write left out.
- Returns
- Total over-budget callback count since boot.
cccdMailboxOverwriteCount() #
CCCD changes that gave way to a newer one in a full mailbox.
- Returns
- CCCD changes dropped since boot.
consumeAuthPending() #
Atomically read-and-clear the auth-complete pending flag. When it returns true, addrOut is filled with the peer address that just authenticated.
- Parameters
-
Name Direction Meaning addrOut out 6-byte peer identity address. addrTypeOut out Address type (0 = public, 1 = random). freshPairingOut out True when the link paired (a numeric comparison ran on it), false when it restored a stored key.
- Return values
-
Value Meaning true A pending auth event was present and consumed; outputs are populated. false No pending auth event.
consumeCccdPending() #
Take the oldest CCCD change the subscribe callback parked.
- Parameters
-
Name Direction Meaning out out Receives the change and the link state it came on.
- Return values
-
Value Meaning true A change was taken. false No change is parked.
- Note
- Runs on the main task, after the connect and auth drains.
consumeConnectPending() #
Atomically read-and-clear the connect pending flag. When it returns true, addrOut, addrTypeOut, and mtuOut describe the peer from the onConnect callback.
- Parameters
-
Name Direction Meaning addrOut out 6-byte peer identity address. addrTypeOut out Address type (0 = public, 1 = random). mtuOut out Negotiated ATT MTU.
- Return values
-
Value Meaning true A pending connect event was present and consumed; outputs are populated. false No pending connect event.
consumeDisconnectPending() #
Atomically read-and-clear the disconnect pending flag.
- Return values
-
Value Meaning true A pending disconnect event was present and consumed. false No pending disconnect event.
consumeUnstoredPairing() #
Atomically read-and-clear a confirmed pairing the keystore did not keep.
- Parameters
-
Name Direction Meaning addrOut out 6-byte peer identity address. resultOut out Why its keys were not kept.
- Return values
-
Value Meaning true One was pending and consumed; outputs are populated. false None pending.
deinitFull() #
Stop advertising, disconnect any peer (waits up to 1500 ms), then fully deinitialize the host stack. Resets all link-state.
- Parameters
-
Name Direction Meaning peerWasConnected out Set to true if a peer was active when called; used by the bond layer to decide whether to flush NVS post-deinit.
deleteBond() #
Delete a runtime NimBLE bond by identity address.
- Parameters
-
Name Direction Meaning addr in 6-byte peer identity address. addrType in 0 = public, 1 = random.
- Return values
-
Value Meaning true The bond was found and deleted. false No matching bond existed or delete failed.
deletePublicBond() #
Delete a runtime NimBLE bond using a public-address fallback.
- Parameters
-
Name Direction Meaning addr in 6-byte peer address (interpreted as public).
- Return values
-
Value Meaning true The bond was found and deleted. false No matching bond existed or delete failed.
dropLinkOf() #
Drop the live link when its peer is addr (NimBleHostPort::).
- Parameters
-
Name Direction Meaning addr in 6-byte peer identity address.
dropRepairLink() #
Drop the link of the host whose re-pair the owner allowed.
- Note
- Core 0 (
ble::).stack:: BleStackTask
formatSecurityTrace() #
Render a security trace into out.
- Parameters
-
Name Direction Meaning out out Destination buffer; always NUL-terminated on success. outLen in Capacity of outin bytes.
- Returns
- Number of bytes written excluding the NUL terminator.
gateRefusalSlot() #
The count slot of a keystore verdict.
- Parameters
-
Name Direction Meaning verdict in The gate's verdict on a peer record.
- Returns
- Its place in kGateRefusedVerdicts; kGateNoSlot for
Storeor a value not listed.
hostAdmits() #
Pure decision: whether a call may enter the host.
- Parameters
-
Name Direction Meaning phase in The host's phase. need in What the call needs to exist. caller in Which task makes the call. identity in Whether a sync has built the identity context.
- Returns
- true when the host's memory the call touches exists, and stays until the call leaves.
hostDrainOverrunCount() #
Teardowns that freed the host with a caller from another task still inside it, the drain before the free having run out (since boot).
- Returns
- The count; 0 on a sound board.
hostKeyboardLeds() #
The keyboard LED byte the host last wrote on the live link.
- Returns
- Its bits; 0 when it wrote none.
hostKeyboardLedWrites() #
How many keyboard LED writes the host has made, on any link.
- Returns
- The count; it never goes back, so a change of it means a new write.
hostLinkInfo() #
Fill out with a cheap snapshot of the live host link.
- Parameters
-
Name Direction Meaning out out Receives own address, connection params and live security state.
- Note
- Any task; read-only (no HCI round-trip).
init() #
Initialize NimBLE, build the HID service, start advertising.
- Parameters
-
Name Direction Meaning deviceName in BLE device name string (NUL-terminated). fastAdvertising in true = 30 ms interval; false = 160 ms (power saving). pairingWindowOpen in The session opens the "add a new host" window, in force from the first advertising.
- Return values
-
Value Meaning true Init succeeded and advertising is running. false NimBLE was already initialized or init failed.
injectNumericComparison() #
Inject the user's Numeric Comparison decision into the link that asked.
- Parameters
-
Name Direction Meaning connHandle in The connection the request was armed for. generation in The generation of the request the owner answered. accept in true to confirm the passkey; false to reject.
- Return values
-
Value Meaning true The decision was applied successfully. false The decision could not be applied (that link is gone or no longer asks that request, or the stack is not ready).
isAdvertising() #
True while the host is actively advertising.
- Return values
-
Value Meaning true A NimBLE advertising set is enabled. false The host is not currently advertising.
isAuthenticated() #
True when the link is encrypted and MITM-authenticated.
- Return values
-
Value Meaning true LE Secure Connections Numeric Comparison succeeded. false Link is not yet encrypted/ authenticated.
isConnected() #
True when a peer connection is up (link layer).
- Return values
-
Value Meaning true A peer has a live BLE connection. false No peer is currently connected.
isInitialized() #
True once NimBLE has been initialized.
- Return values
-
Value Meaning true init()has succeeded and the host is up.false Pre-init or post-deinit.
isPairing() #
True while a pairing is under way on the live link.
- Return values
-
Value Meaning true The link raised a numeric comparison (or the owner allowed its re-pair) and its encryption has neither completed nor failed, nor has the owner refused the comparison. false No pairing on the link: none started, it ended, or no link.
isPairingWindowOpen() #
True while the "add a new host" pairing window is open.
- Return values
-
Value Meaning true Advertising is open to any central. false Bonded-only accept-list is enforced once a host is bonded.
isShuttingDown() #
True while a full teardown is in progress.
- Return values
-
Value Meaning true Between deinitFull()entry and the actual deinit completion.false Stack is idle or fully deinitialized.
isSynced() #
True once the host+controller have synced (the onSync callback ran).
Strictly later than isInitialized(): init() returns as soon as the host task is spawned, but the bond store and ble_ only become writable after sync. Deferred bond deletions must gate on this, not on isInitialized().
- Return values
-
Value Meaning true The controller is ready; bond operations take effect. false Pre-sync (or post-deinit / mid-reset).
judgedCode() #
The judge code of a timing step.
- Parameters
-
Name Direction Meaning step in The step.
- Returns
- 1..4, its place in kJudgedSteps plus one; 0 for a step not listed.
keepRepairIdentityKey() #
Keep the identity key of the host whose re-pair the owner allowed, before its old bond is deleted.
- Return values
-
Value Meaning true The old bond held one, and it is kept. false It held none: no pairing under those bytes is stored until the approval ends.
- Note
- Core 0 (
ble::).stack:: BleStackTask
numericComparisonLinkAdmitted() #
True when a yes to a comparison raised on connHandle may confirm it.
- Parameters
-
Name Direction Meaning connHandle in The link the request was armed for.
- Return values
-
Value Meaning true It is the live link the host filter admitted. false It is gone, another link is current, or the filter drops it.
ownAddressRefused() #
Whether the advertising is refused because privacy could not be set up.
- Return values
-
Value Meaning true A shipping build refused to advertise with its identity address. false Privacy is on, or the build allows the fallback.
ownerStartsNow() #
Whether the owner's start may start an advertising set now.
A link NimBLE holds keeps its slot (one connection, CONFIG_): its end restarts advertising (the drain after a disconnect, the end of a link the host filter dropped, a failed attempt), and a start made under it would only be refused (ble_).
- Parameters
-
Name Direction Meaning linkInHost in NimBLE holds a connection, whatever its stage.
- Return values
-
Value Meaning true Start now. false Leave it to the link's end.
packJudgedTiming() #
Pack a timing judge into one word.
- Parameters
-
Name Direction Meaning step in The step the judge took. live in The timing it judged.
- Returns
- code << 48 | interval << 32 | latency << 16 | timeout; never 0 for a listed step.
persistedNativeBondCount() #
Count the bonds NimBLE persisted in NVS, readable while the radio is OFF.
BLE is on-demand on Kleidos: at boot and in PIN_ENTRY the stack is OFF, so readNativeBonds() — which queries the live NimBLE bond store — refuses 0 even though the LTKs are intact in NVS (CONFIG_). That OFF-window 0 has repeatedly read as "bonds dropped on reboot" in QA when the bonds in fact survive. This helper reads the persisted count directly out of NimBLE's own bond storage (counting the stored peer security records) through the platform NVS facade, so a diagnostic can report the durable bond count when the live stack is down.
- Warning
- Reads NVS, so it is only safe while BLE is fully OFF — it returns 0 when the stack is up (use readNativeBonds() then) to honor the "NVS only when the radio is down" discipline.
- Returns
- Number of bonds persisted in NimBLE's NVS store, or 0 when the radio is up, on native builds, or on any NVS error.
protocolMode() #
Currently selected HOGP Protocol Mode.
- Returns
- 0x00 = Boot Protocol, 0x01 = Report Protocol (default).
readNativeBonds() #
Read every NimBLE-persisted bond in one pass, or say it could not.
The stack's own view, independent of the Kleidos bond table (kleidos::), and the only live keystore read: false means the keystore was not read (stack down, being torn down, or the store refused), never that it is empty.
- Parameters
-
Name Direction Meaning out out Bonds read. capacity in Entries outholds.count out Bonds written (0 on failure).
- Return values
-
Value Meaning true The keystore was read. false It could not be read.
readPersistedBonds() #
Read the bonds the keystore persisted, with the radio fully off (NimBleHostPort::).
- Parameters
-
Name Direction Meaning out out Bonds read. capacity in Entries outholds.count out Bonds written (0 on failure).
- Return values
-
Value Meaning true The persisted store was read (0 bonds when none was stored). false It could not be read, or the radio is not fully off.
releaseAllKeys() #
Send one all-zero keyboard report, so the host holds no key.
- Return values
-
Value Meaning true It went out, or no link is up to hold a key. false It did not; the link was ended, which lifts every key too.
repairHostPaired() #
Whether the live link is the allowed host's fresh pairing.
- Return values
-
Value Meaning true The host whose re-pair the owner allowed paired fresh on it. false Another host, a restored key, or no link.
repairPeer() #
The identity of the bonded host that raised the re-pair prompt.
- Parameters
-
Name Direction Meaning addrOut out The identity address (6 bytes). addrTypeOut out Its address type.
- Return values
-
Value Meaning true A host asked, and its identity was written. false No re-pair prompt stands.
reportsSentCount() #
Total HID keystroke reports successfully sent since boot.
- Returns
- Cumulative successful
sendReport()count.
sendReport() #
Send an 8-byte HID keyboard report.
- Parameters
-
Name Meaning modifiers Modifier byte (Shift, Ctrl, Alt, etc.). keycode HID usage code for the key.
- Return values
-
Value Meaning true The report was queued or delivered to the input characteristic. false The link is not up or the input characteristic is unavailable.
setBatteryLevel() #
Set the battery level the Battery Level characteristic serves.
- Parameters
-
Name Direction Meaning level in Battery level, 0..100 % (the main loop's sample, never a chip read of the host's own).
- Note
- Any task; lock-free. Kept across a teardown.
setPairingWindow() #
Open or close the "add a new host" pairing window.
Open = advertise to any central so a brand-new host can pair; closed (default) = once at least one host is bonded, only bonded identities may hold the link, so a central that is not bonded cannot pair and pose as a host. Restarts a running advertising set only when its filter changes and no link is at any stage; otherwise the next start applies it.
- Parameters
-
Name Direction Meaning open in true to open the pairing window; false to enforce bonded-only.
- Note
- Preferred on Core 0 (
ble::).stack:: BleStackTask
setPortForTest() #
Native-only: inject the NimBleHostPort the host:: shim forwards to.
Lets unit tests drive the upper BLE layers against a FakeNimBleHostPort without any NimBLE coupling. Has no device build (production always resolves the NimBleHostAdapter singleton).
- Parameters
-
Name Direction Meaning port in The fake port to forward to (must outlive the calls).
startAdvertising() #
Start (or restart) advertising.
- Parameters
-
Name Direction Meaning fastAdvertising in true = 30 ms interval; false = 160 ms (power saving).
- Note
- Preferred on Core 0 (
ble::).stack:: BleStackTask
stopFailedSession() #
Stop a failed session: its advertising, and its link if it never secured.
Holds advertising until the owner's next start and ends a live link that is not secured by now (finding C11). Only for a session that failed: a pairing in progress goes with it.
- Note
- Preferred on Core 0 (
ble::).stack:: BleStackTask
storeWriteCount() #
Number of keystore write callbacks timed.
Every call, the records the gate refuses (which reach no NVS) included.
- Returns
- Keystore write callbacks since boot.
storeWriteMaxUs() #
Worst-case keystore write wall time (NimBLE's NVS persistence of a bond).
- Returns
- Max keystore write time in microseconds since boot.
sweepStoreOrphans() #
Delete every stored record no whole bond owns (NimBleHostPort::).
- Returns
- What was removed and added; all zero when nothing was read.
unpackJudgedTiming() #
Unpack a word packJudgedTiming made.
- Parameters
-
Name Direction Meaning word in The word; 0 when the link was not judged.
- Returns
- The judge; all zero for 0.
windowRestartFor() #
Whether a change of the pairing window restarts the running set.
A link at any stage comes first: no stop is ever made under it.
- Parameters
-
Name Direction Meaning view in What the adapter knows.
- Returns
- The verdict.
Variable Documentation
kCallbackBudgetUs #
A host callback longer than this is counted as over budget (µs). Five milliseconds is a host-responsiveness budget for the GAP event and attribute callbacks. Connection events run in the controller, at a higher priority than the host task, so a host callback past it delays the host's processing of the next event; it does not make the link miss one. NimBLE's NVS persistence of a bond is counted apart (store_max_us).
kDeinitDisconnectWaitMs #
The wait for the peer-disconnect GAP event after ble_, so a peer that never acknowledges the disconnect cannot wedge the shutdown.
kDeinitDrainBudgetMs #
Each of the two waits for the callers already inside the host to leave: one before nimble_, one before nimble_ frees the host. Each caller is one short host call, a few ms at most.
kGateRefusedVerdicts #
The keystore verdicts the gate refuses, in the order of their count slots (unconfirmed, bad_identity, identity_
kHostStopBudgetMs #
nimble_ on a controller that does not answer: one HCI command timeout (NimBLE's BLE_, 2 s), which a stop still meets when the host did not sync within kStopSyncWaitMs.
kJudgedSteps #
The timing steps in the order of their judge codes 1..4 (settled, ask_again, end_link, keep); code 0 is "not judged".
kStopSyncWaitMs #
The wait for the host's first sync before nimble_. The host task runs its startup HCI sequence until the sync (some 70 ms after the host is built, on both chip families), and ble_hs_stop() marks the host off at once when no link is up, after which the HCI transport drops every controller reply: a startup command then waits out its whole HCI timeout. Letting the sync land first makes that stop take tens of ms.
kTeardownSlackMs #
The rest of the teardown on the BLE stack task (nimble_, the state reset, the command hand-off) and the facade's 20 ms polls.