pub enum GattsEvent<'a> {
Register(BleGattRegister),
Read {
conn_handle: ConnHandle,
attr_handle: AttrHandle,
offset: u16,
reply: Mbuf<'a>,
},
Write {
conn_handle: ConnHandle,
attr_handle: AttrHandle,
data: Mbuf<'a>,
},
SubscriptionChanged {
conn_handle: ConnHandle,
attr_handle: AttrHandle,
reason: SubscribeReason,
prev_notify: bool,
cur_notify: bool,
prev_indicate: bool,
cur_indicate: bool,
},
NotifyComplete {
conn_handle: ConnHandle,
attr_handle: AttrHandle,
indication: bool,
status: i32,
},
}Expand description
A GATT-server event, delivered on the host task to the single
gatts_subscribe hook.
There are no per-characteristic callbacks: NimBLE dispatches every characteristic read and
write through one shared trampoline, and they arrive here as Read /
Write, keyed by the globally-unique attr_handle. The
Register variants fire as the service table is registered (at start).
SubscriptionChanged and NotifyComplete
are server-role connection events that NimBLE delivers on the GAP callback and we demux here.
The hook returns the ATT status (0 on success) for Read/Write; the return is ignored for
the others.
Variants§
Register(BleGattRegister)
Read
A peer is reading one of our characteristics; append the value to reply.
This covers every ATT read (Read Request, Read Blob Request, Read By Type Request, Read
Multiple Request) — NimBLE reports them all the same way — as well as local reads, which
carry CONN_HANDLE_NONE instead of a real connection.
Fields
conn_handle: ConnHandleattr_handle: AttrHandleoffset: u16Non-zero only for a long read (ATT Read Blob Request), where it is the offset the peer is asking to continue from.
Always append the whole value regardless of this field: NimBLE hands a long read a
scratch buffer and slices [offset..] out of it itself. The offset is informational —
use it to tell a continuation from a fresh read (e.g. to snapshot the value at offset
0 so a multi-blob read stays coherent).
Always 0 on ESP-IDF < 5.3, where NimBLE does not report the offset at all.
Write
A peer wrote one of our characteristics.
This covers every ATT write — Write Request, Write Command (write-without-response), Signed
Write Command, and a completed Prepare/Execute long write (NimBLE coalesces the queued
fragments into one event) — as NimBLE does not report which opcode carried the write. It
need not be distinguished: for a Write Request the status returned by the hook becomes the
ATT error response, and for a Write Command (which has no response) it is discarded. Local
writes arrive here too, with CONN_HANDLE_NONE.
SubscriptionChanged
A peer’s subscription state for one of our characteristics changed: it wrote the CCCD, the
connection is going down, or a bond was restored — see reason. The prev_* / cur_*
pairs give the edge, so no shadow state is needed to tell a subscribe from an unsubscribe.
Fields
conn_handle: ConnHandleattr_handle: AttrHandlereason: SubscribeReasonprev_notify: boolcur_notify: boolprev_indicate: boolcur_indicate: boolNotifyComplete
An indication/notification we sent completed (for an indication, status is the peer’s
confirmation result).