aliro_ble_central_nimble.c
NimBLE central/client backend for the Aliro initiator: the mirror of…
Overview
NimBLE central/client backend for the Aliro initiator: the mirror of components/aliro_ble/aliro_ble.c. That file advertises 0xFFF2, serves the characteristics and runs a CoC server; this one scans for 0xFFF2, connects, discovers, reads the reader's SPSM/versions, writes the selected version and opens a CoC client to that SPSM.
flowchart TD abandon --> reset_peer abandon --> start_scan
API
Fstatic void reset_peer(void)
Clear the peer state structure and reset the connection handle to BLE_HS_CONN_HANDLE_NONE.
abandon, aliro_ble_central_start, gap_eventFstatic void abandon(const char *why, int rc)
Abandon this peer and go back to scanning. Called from every failure path so a half-finished chain can never leave the app wedged.
coc_connect, gap_event, l2cap_event_cb, on_chr_disc, on_devver_write, on_spsm_read, on_svc_disc · calls reset_peer, start_scanFstatic int coc_arm_rx(struct ble_l2cap_chan *chan)
Allocate and arm an RX buffer on the L2CAP CoC channel. Return BLE_HS_ENOMEM if no buffers are available, otherwise return the ble_l2cap_recv_ready result.
l2cap_event_cbFstatic void coc_connect(void)
Final step of the chain: open the CoC to the SPSM the READ gave us.
on_devver_write · calls abandonFstatic int on_devver_write(uint16_t conn_handle, const struct ble_gatt_error *error, struct ble_gatt_attr *attr, void *arg)
Callback when the device-version characteristic write completes. On success, open the L2CAP CoC channel to the SPSM previously read. On error, abandon this peer.
abandon, coc_connectFstatic int on_spsm_read(uint16_t conn_handle, const struct ble_gatt_error *error, struct ble_gatt_attr *attr, void *arg)
GATT read callback for the reader SPSM characteristic: parse the flat payload to extract SPSM, supported versions, and features. Verify that the peer publishes the selected version. Write the selected version and a features byte to the device-version characteristic. On any error, abandon this peer.
abandonFstatic int on_chr_disc(uint16_t conn_handle, const struct ble_gatt_error *error, const struct ble_gatt_chr *chr, void *arg)
GATT characteristic discovery callback: record the val_handle of the SPSM and device-version characteristics. On discovery completion, read the SPSM characteristic. On error, abandon this peer and return to scanning.
abandonFstatic int on_svc_disc(uint16_t conn_handle, const struct ble_gatt_error *error, const struct ble_gatt_svc *service, void *arg)
GATT service discovery callback: record the service handle range for the 0xFFF2 Aliro service. On discovery completion, discover all characteristics within that range. On error, abandon this peer.
abandonFstatic bool advert_is_our_reader(const struct ble_hs_adv_fields *fields)
True when this advert carries Aliro service data from the reader we want. The reader falls back to a bare UUID + name when unprovisioned or GRK-less (aliro_ble.c:589); that form has no group id to match, so it is skipped quietly rather than treated as an error.
gap_eventFstatic void start_scan(void)
Configure and start BLE GAP active scanning with duplicate filtering disabled (the dynamic tag changes). Return to scanning after connection or on error.
abandon, gap_event, on_syncFstatic void on_reset(int reason)
Log that the NimBLE stack has reset and include the reset reason code.
Fstatic void host_task(void *param)
Run the NimBLE host event loop in the current thread until shutdown, then deinitialize the FreeRTOS integration.
Fstatic int coc_pools_init(void)
Initialize the mbuf pool for CoC data: create a memory pool and mbuf pool with the configured buffer count and MTU. Return 0 on success or -1 if either pool initialization fails.
aliro_ble_central_startFint aliro_ble_central_send(uint16_t conn_handle, const uint8_t *data, size_t len)
Send data to the peer over the L2CAP CoC: allocate an mbuf, append the data, and submit it via ble_l2cap_send. Return 0 on success (stack owns the buffer or it is queued); return -1 on failure (buffer freed on error).
Undocumented (4)
l2cap_event_cb, gap_event, on_sync, aliro_ble_central_start