openaliro
Aliro reader: UWB/CCC core and ESP32-S3/C5/C6 port
Loading...
Searching...
No Matches
aliro_ble.h
1// Aliro BLE-UWB reader transport: GATT service definition, advertised feature flags, and transport
2// callbacks connecting the BLE peripheral role to the Aliro protocol handler in aliro_reader.
3// Callers configure the transport via aliro_ble_prepare (which builds the READ characteristic
4// payload without touching NimBLE), then register the GATT service returned by
5// aliro_ble_service_def with the host's combined service table.
6/*
7 * Copyright (c) 2026 asxeem
8 * SPDX-License-Identifier: ISC
9 *
10 * aliro_ble — Aliro BLE transport (NimBLE) for the ESP32-S3 port.
11 * Advertises the Aliro GATT service, negotiates the BLE-UWB protocol version,
12 * and carries the Aliro transaction over an L2CAP CoC. Independent
13 * reimplementation; see SPEC.md for the wire protocol and provenance.
14 */
15#pragma once
16#include <stddef.h>
17#include <stdint.h>
18#include <stdbool.h>
19
20#ifdef __cplusplus
21extern "C" {
22#endif
23
27 bool timesync_procedure_0;
28 bool timesync_procedure_1;
29 bool le_coded_phy;
30};
31
35 void (*on_data)(uint16_t conn_handle, const uint8_t *data, uint16_t len);
37 void (*on_connected)(uint16_t conn_handle);
38 void (*on_disconnected)(uint16_t conn_handle);
42 void (*on_rssi)(uint16_t conn_handle, int8_t rssi_dbm);
43};
44
49 const uint16_t *proto_versions;
50 size_t proto_versions_count;
51 struct aliro_ble_features features;
52 struct aliro_ble_callbacks cb;
53};
54
57int aliro_ble_start(const struct aliro_ble_config *cfg);
58
60uint16_t aliro_ble_spsm(void);
61
63int aliro_ble_send(uint16_t conn_handle, const uint8_t *data, size_t len);
64
67int aliro_ble_disconnect(uint16_t conn_handle);
68
69/* Marshal a reader->phone status send onto the NimBLE host task (where every sc_ble
70 * seal + L2CAP send already runs), so a caller on another task can send without racing
71 * the BleSK counter. `cb` runs on the host task and is passed `unsecured`. */
72void aliro_ble_post_reader_status(void (*cb)(bool unsecured), bool unsecured);
73
74/* Marshal a presence-proof reset onto the NimBLE host task. The callback may
75 * inspect the reader session table and terminate links without racing the
76 * transaction callbacks that own it. Only one proof command is served at a
77 * time by the console, so one queued callback slot is sufficient. */
78void aliro_ble_post_presence_reset(void (*cb)(void));
79
80/* ---- Attach mode: share a NimBLE host another stack already owns ---------- *
81 * Instead of owning NimBLE (aliro_ble_start), the reader can attach to a host
82 * brought up by e.g. esp-matter, so both coexist on one controller. Three
83 * phases: prepare() captures the config; the owner registers our GATT service
84 * (aliro_ble_service_def()) through its extra-services hook BEFORE it starts its
85 * GATT server; start_attached() brings up the L2CAP CoC + advertising once the
86 * host is synced and the owner has released the advertiser (post-commissioning). */
87struct ble_gatt_svc_def; /* NimBLE type, opaque here */
88
90int aliro_ble_prepare(const struct aliro_ble_config *cfg);
91
94const struct ble_gatt_svc_def *aliro_ble_service_def(void);
95
98int aliro_ble_start_attached(void);
99
105void aliro_ble_set_adv_params(const uint8_t group_id8[8], const uint8_t sub_id2[2],
106 const uint8_t grk[16], int8_t tx_power);
107
111void aliro_ble_readvertise(void);
112
116void aliro_ble_time_updated(void);
117
118#ifdef __cplusplus
119}
120#endif
Transport callbacks into the app / Phase-3 Aliro handler.
Definition aliro_ble.h:33
void(* on_connected)(uint16_t conn_handle)
L2CAP channel opened / closed for a peer (2.2+).
Definition aliro_ble.h:37
void(* on_data)(uint16_t conn_handle, const uint8_t *data, uint16_t len)
An L2CAP SDU arrived from the peer (2.2+).
Definition aliro_ble.h:35
void(* on_rssi)(uint16_t conn_handle, int8_t rssi_dbm)
Connection-RSSI sample (dBm), polled while the CoC is up.
Definition aliro_ble.h:42
Reader configuration.
Definition aliro_ble.h:48
Aliro BLE-UWB supported-features flags (advertised in the READ char, and parsed from the device WRITE...
Definition aliro_ble.h:26