aliro_ble_zephyr.c
depends on matter_ble_zephyr.h matter_commission.h
flowchart TD aliro_advertise --> build_aliro_svc_data
API
Cstatic struct aliro_coc
One peer at a time. CONFIG_BT_MAX_CONN=1 makes that a build-time fact, not a hope, so a single channel record is the whole table.
Fstatic uint16_t conn_to_handle(struct bt_conn *conn)
The reader engine's transport handle. Zephyr identifies a link by pointer, the seam by uint16_t, so hand out the connection index (0..MAX_CONN-1).
coc_connected, coc_disconnected, coc_recvFstatic struct net_buf *coc_alloc_buf(struct bt_l2cap_chan *chan)
Allocate a receive net_buf from the CoC pool with no wait.
Fstatic int coc_recv(struct bt_l2cap_chan *chan, struct net_buf *buf)
Forward received L2CAP CoC data to the registered on_data callback as a transport handle and byte buffer.
conn_to_handleFstatic void coc_connected(struct bt_l2cap_chan *chan)
Handle L2CAP CoC connection establishment by notifying the Aliro engine and logging the event.
conn_to_handle, on_connectedFstatic void coc_disconnected(struct bt_l2cap_chan *chan)
Handle L2CAP CoC disconnection by releasing the channel, clearing state, and notifying the Aliro engine.
conn_to_handle, on_disconnectedFstatic int coc_accept(struct bt_conn *conn, struct bt_l2cap_server *server, struct bt_l2cap_chan **chan)
Accept an incoming L2CAP CoC connection if no channel is in use, allocate it to the static instance, initialize its MTU and callback ops, and bind it to the peer connection.
Fstatic uint8_t encode_features(const struct aliro_ble_features *f)
Encode Aliro feature flags (timesync procedures 0 and 1, LE Coded PHY) into a byte bitmap for the service data advertisement.
build_read_payloadFstatic void build_read_payload(const struct aliro_ble_config *cfg)
Build the Aliro BLE advertisement payload containing the L2CAP SPSM, supported protocol versions, and feature flags.
aliro_ble_prepare · calls encode_featuresFstatic ssize_t reader_spsm_read(struct bt_conn *conn, const struct bt_gatt_attr *attr, void *buf, uint16_t len, uint16_t offset)
GATT read callback that returns the static Aliro reader payload (service data with identity material and features).
Fstatic ssize_t device_ver_write(struct bt_conn *conn, const struct bt_gatt_attr *attr, const void *buf, uint16_t len, uint16_t offset, uint8_t flags)
The peer writes the BLE-UWB protocol version it selected. Both shipped readers require at least 3 bytes here (see 588df2e); we only need to accept it, the reader engine reads the selection off the transaction itself.
Fstatic bool build_aliro_svc_data(uint8_t out[24])
Aliro 1.0 section 11.3 (Table 11-2). 24 payload bytes after the 16-bit UUID: [0] flags: bit7 = BLE+UWB supported, bits2:0 = version (0) [1] tx power (int8) [2..9] truncated reader group id = reader_id[0..7] [10..11] truncated reader group sub id = reader_id[16..17] [12..15] dynamic-tag expiry, big-endian (0xFFFFFFFF = no clock) [16] reserved [17..23] dynamic tag The derivation wants the identity address MSB-first; bt_id_get hands it out LSB-first, same as NimBLE.
aliro_advertiseFstatic int aliro_advertise(void)
Advertise the Aliro reader service or Matter commissioning availability over BLE, with payload priority given to findability: reader service when commissioned, commissioning advertisement when unprovisioned or a window is open, or bare service UUID as fallback. Stops advertising if a connection is active and schedules re-advertisement on disconnect.
aliro_ble_readvertise, aliro_ble_start, aliro_ble_time_updated, readvertise_work_fn · calls build_aliro_svc_dataFstatic void readvertise_work_fn(struct k_work *w)
Attempt to resume BLE advertising with exponential backoff (100 ms, max 5 attempts) when a disconnect requires re-advertisement; runs on the system work queue to avoid blocking the Aliro access protocol.
aliro_advertiseFstatic void on_connected(struct bt_conn *conn, uint8_t err)
Mark the BLE connection established on successful controller completion, noting that the callback fires for every connection attempt including those about to fail.
coc_connectedFstatic void on_disconnected(struct bt_conn *conn, uint8_t reason)
Mark the BLE connection dropped, count establishment failures and report them in one log line when the run ends, then schedule re-advertisement.
coc_disconnectedFint aliro_ble_prepare(const struct aliro_ble_config *cfg)
Validate and store Aliro BLE configuration: protocol versions and callback handler. Caller must provide non-null cfg with non-empty proto_versions array sized <= ALIRO_MAX_VERSIONS; returns 0 on success or -EINVAL if any parameter is invalid.
aliro_ble_start · calls build_read_payloadFuint16_t aliro_ble_spsm(void)
Return the L2CAP protocol/service multiplexer for the Aliro reader channel.
Fint aliro_ble_send(uint16_t conn_handle, const uint8_t *data, size_t len)
Send an APDU over the active L2CAP CoC link; fails if not connected. Copies data into a reserved net_buf and asserts the payload fits the pool buffer to catch oversized framing from the reader itself.
Fint aliro_ble_disconnect(uint16_t conn_handle)
Disconnect the active L2CAP CoC link, terminating the Aliro protocol exchange.
Fvoid aliro_ble_set_adv_params(const uint8_t group_id8[8], const uint8_t sub_id2[2], const uint8_t grk[16], int8_t tx_power)
Store the Aliro reader identity material (group ID, sub ID, GRK, TX power) to populate the service data advertisement on the next readvertise call.
Fvoid aliro_ble_readvertise(void)
Re-advertise the Aliro reader service or Matter commissioning availability over BLE after a state change requiring advertisement resume.
aliro_advertiseFvoid aliro_ble_time_updated(void)
Re-advertise the Aliro reader service or Matter commissioning availability over BLE after the system time is updated.
aliro_advertiseFstatic void status_work_fn(struct k_work *w)
Deferred work callback that invokes the reader status callback with the unsecured flag if set.
Fstatic void presence_work_fn(struct k_work *w)
Deferred work callback that invokes the presence reset callback if set.
Fvoid aliro_ble_post_reader_status(void (*cb)(bool unsecured), bool unsecured)
Queue a reader status callback with unsecured state to run asynchronously on the work queue.
Fvoid aliro_ble_post_presence_reset(void (*cb)(void))
Queue a presence reset callback to run asynchronously on the work queue.
Fconst struct ble_gatt_svc_def *aliro_ble_service_def(void)
Attach mode exists only so the ESP32 reader can share a NimBLE host with esp-matter. Nothing shares this host.
Fint aliro_ble_start_attached(void)
Not supported on this target; returns ENOTSUP.
Undocumented (1)
aliro_ble_start