|
|
| enum class | Properties : std::uint16_t {
kNone = 0x0000
, kWritePermissionBit0 = 0x0001
, kRead = 0x0002
, kWriteWithoutResponse = 0x0004
,
kWrite = 0x0008
, kWritePermissionBit1 = 0x0010
, kReadPermissionSc = 0x0020
, kAuthenticatedSignedWrite = 0x0040
,
kWritePermissionSc = 0x0080
, kDynamic = 0x0100
, kUuid128 = 0x0200
, kReadPermissionBit0 = 0x0400
,
kReadPermissionBit1 = 0x0800
, kEncryptionKeySizeMask = 0xF000
} |
| | Attribute flags with direct BTstack ATT_PROPERTY_* mapping. More...
|
| |
| using | ReadCallback = std::function< uint16_t(uint16_t offset, uint8_t *buffer, uint16_t buffer_size)> |
| | Callback type for reading attribute value. Parameters: offset, destination buffer, buffer size Returns: number of bytes read, or ATT error code if > 0xfe00.
|
| |
| using | WriteCallback = std::function< BleError(uint16_t offset, const uint8_t *data, uint16_t size)> |
| | Callback type for writing attribute value. Parameters: offset, source data, data size Returns: BleError code (BleError::kSuccess = success)
|
| |
|
|
| | Attribute ()=default |
| | Default-construct an invalid attribute.
|
| |
| | Attribute (Attribute &&) noexcept=default |
| | Move constructor (transfers storage and callbacks).
|
| |
| Attribute & | operator= (Attribute &&) noexcept=default |
| | Move assignment operator (transfers storage and callbacks).
|
| |
| | Attribute (const Uuid &uuid, uint16_t properties, uint16_t handle=0) |
| | Construct an attribute with a UUID and properties.
|
| |
| | Attribute (const Uuid &uuid, uint16_t properties, const uint8_t *data, size_t size, uint16_t handle=0) |
| | Construct an attribute with a UUID, properties, and value data.
|
| |
|
| uint16_t | GetHandle () const |
| | Get the ATT handle.
|
| |
| void | SetHandle (uint16_t handle) |
| | Set the ATT handle.
|
| |
| const Uuid & | GetUuid () const |
| | Get the attribute UUID.
|
| |
| bool | IsUuid128 () const |
| | Check if the attribute UUID is 128-bit.
|
| |
| bool | IsValid () const |
| | Check if this attribute has a valid handle and UUID.
|
| |
| bool | IsThisAttribute (const Uuid &uuid) const |
| | Check if this attribute matches a UUID.
|
| |
| bool | IsThisAttribute (uint16_t handle) const |
| | Check if this attribute matches a handle.
|
| |
| bool | IsThisAttribute (const Uuid &uuid, uint16_t handle) const |
| | Check if this attribute matches both UUID and handle.
|
| |
|
| uint16_t | GetProperties () const |
| | Get the properties bitmask of the attribute.
|
| |
| void | SetProperties (uint16_t properties) |
| | Set the properties bitmask of the attribute.
|
| |
|
| const std::vector< uint8_t > & | GetDynamicValue () const |
| | Get value as vector (for compatibility). Note: Returns empty for static attributes because they are DB-backed.
|
| |
| const uint8_t * | GetValueData () const |
| | Get pointer to attribute value data.
|
| |
| size_t | GetValueSize () const |
| | Get size of attribute value.
|
| |
| bool | SetValue (const uint8_t *data, size_t size) |
| | Set attribute value. Only allowed for dynamic attributes; static attributes are immutable because their bytes reside in the ATT DB image.
|
| |
| bool | SetStaticValue (const uint8_t *data, size_t size) |
| | Set attribute value for static attributes. Copies the data into owned storage and updates the static value pointer.
|
| |
| bool | SetValue (std::vector< uint8_t > &&data) |
| | Set attribute value from rvalue vector (move semantics). Only allowed for dynamic attributes.
|
| |
| bool | SetValue (const std::vector< uint8_t > &data) |
| | Set attribute value from lvalue vector (copy semantics). Only allowed for dynamic attributes.
|
| |
| bool | SetStaticValue (const std::vector< uint8_t > &data) |
| | Set attribute value for static attributes from vector (copy semantics).
|
| |
| template<typename T > |
| bool | SetValue (const T &value) |
| | Set attribute value from a typed value (generic template). Converts any trivial type to bytes and stores as the attribute value. Only allowed for dynamic attributes.
|
| |
|
| void | SetReadCallback (ReadCallback callback) |
| | Set the read callback for this attribute. Called when a remote client reads this attribute.
|
| |
| bool | HasReadCallback () const |
| | Check if a read callback is registered.
|
| |
| uint16_t | InvokeReadCallback (uint16_t offset, uint8_t *buffer, uint16_t buffer_size) const |
| | Invoke the read callback.
|
| |
| void | SetWriteCallback (WriteCallback callback) |
| | Set the write callback for this attribute. Called when a remote client writes this attribute.
|
| |
| bool | HasWriteCallback () const |
| | Check if a write callback is registered.
|
| |
| BleError | InvokeWriteCallback (uint16_t offset, const uint8_t *data, uint16_t size) |
| | Invoke the write callback.
|
| |
| virtual | ~MovableOnly ()=default |
| |
| | MovableOnly (MovableOnly &&)=default |
| |
| MovableOnly & | operator= (MovableOnly &&)=default |
| |
| | MovableOnly ()=default |
| |
| | NonCopyable (const NonCopyable &)=delete |
| |
| NonCopyable & | operator= (const NonCopyable &)=delete |
| |
| | NonCopyable (NonCopyable &&)=default |
| |
| NonCopyable & | operator= (NonCopyable &&)=default |
| |
|
|
For UUID-only checks, use the corresponding Uuid::Is* helpers.
|
| static bool | IsPrimaryServiceDeclaration (const Attribute &attr) |
| | Check if an attribute is a Primary Service Declaration.
|
| |
| static bool | IsSecondaryServiceDeclaration (const Attribute &attr) |
| | Check if an attribute is a Secondary Service Declaration.
|
| |
| static bool | IsServiceDeclaration (const Attribute &attr) |
| | Check if an attribute is any Service Declaration (Primary or Secondary).
|
| |
| static bool | IsIncludedServiceDeclaration (const Attribute &attr) |
| | Check if an attribute is an Included Service Declaration.
|
| |
| static bool | IsCharacteristicDeclaration (const Attribute &attr) |
| | Check if an attribute is a Characteristic Declaration.
|
| |
| static bool | IsClientCharacteristicConfiguration (const Attribute &attr) |
| | Check if an attribute is a Client Characteristic Configuration Descriptor.
|
| |
| static bool | IsServerCharacteristicConfiguration (const Attribute &attr) |
| | Check if an attribute is a Server Characteristic Configuration Descriptor.
|
| |
| static bool | IsCharacteristicUserDescription (const Attribute &attr) |
| | Check if an attribute is a Characteristic User Description.
|
| |
| static bool | IsCharacteristicExtendedProperties (const Attribute &attr) |
| | Check if an attribute is a Characteristic Extended Properties descriptor.
|
| |
| static bool | IsDescriptor (const Attribute &attr) |
| | Check if an attribute is a descriptor (not declaration or value).
|
| |
|
| static Attribute | PrimaryServiceDeclaration (const Uuid &service_uuid, uint16_t handle=0) |
| | Create a Primary Service Declaration with a service UUID payload.
|
| |
| static Attribute | SecondaryServiceDeclaration (const Uuid &service_uuid, uint16_t handle=0) |
| | Create a Secondary Service Declaration with a service UUID payload.
|
| |
| static Attribute | IncludedServiceDeclaration (uint16_t start_handle, uint16_t end_handle, const Uuid &service_uuid, uint16_t handle=0) |
| | Create an Included Service Declaration payload.
|
| |
| static Attribute | CharacteristicDeclaration (uint8_t properties, uint16_t value_handle, const Uuid &characteristic_uuid, uint16_t handle=0) |
| | Create a Characteristic Declaration payload.
|
| |
| static Attribute | ClientCharacteristicConfiguration (uint16_t value, uint16_t handle=0) |
| | Create a Client Characteristic Configuration with a 16-bit value.
|
| |
| static Attribute | ServerCharacteristicConfiguration (uint16_t value, uint16_t handle=0) |
| | Create a Server Characteristic Configuration with a 16-bit value.
|
| |
| static Attribute | CharacteristicUserDescription (const std::string &description, uint16_t handle=0) |
| | Create a Characteristic User Description with a UTF-8 string.
|
| |
| static Attribute | CharacteristicExtendedProperties (uint16_t value, uint16_t handle=0) |
| | Create a Characteristic Extended Properties with a 16-bit value.
|
| |
| static Attribute | CharacteristicPresentationFormat (uint8_t format, int8_t exponent, uint16_t unit, uint8_t name_space, uint16_t description, uint16_t handle=0) |
| | Create a Characteristic Presentation Format payload (0x2904).
|
| |
| static Attribute | CharacteristicAggregateFormat (const std::vector< uint16_t > &handles, uint16_t handle=0) |
| | Create a Characteristic Aggregate Format from a list of handles.
|
| |
ATT attribute wrapper with BTstack-compatible fields.
This class mirrors a single ATT database entry as used by the RP2040 Pico W BLE stack (BTstack). The fields align with BTstack's binary ATT DB layout parsed by the AttributeServer, so the properties_ bitmask and handle_ values can be populated directly from the stack.
Value storage model:
- Static attributes (no
kDynamic flag): keep a pointer/size pair into the ATT DB blob without copying. This matches BTstack, which treats these values as immutable, fixed-at-compile-time data. Avoiding a copy saves RAM and preserves the DB as the single source of truth.
- Storage:
static_value_ptr_ + static_value_size_ point into the ATT DB image parsed by AttributeServer.
- Mutability: immutable at runtime;
SetValue() rejects writes.
- Access:
GetValueData() returns the DB pointer; GetValueSize() returns the DB length.
- Lifetime: the DB buffer must remain valid for the life of the Attribute; use
SetStaticValue() to own a copy.
- Optional override:
SetStaticValue() repoints static_value_ptr_, allowing a controlled, owned static value without toggling kDynamic.
- Dynamic attributes (
kDynamic set): keep a mutable std::vector that can be updated at runtime. Dynamic attributes rely on callbacks and writable storage; copying into a vector provides ownership and resize capability that a DB-backed pointer cannot offer.
- Storage:
dynamic_value_ owns the bytes and can grow/shrink.
- Mutability:
SetValue() and write callbacks may update contents.
- Access:
GetValueData() returns the vector data pointer; size is dynamic_value_.size().
- Writes:
InvokeWriteCallback() stores data even if no write callback is installed; callbacks are optional for dynamic attributes.
Consequence:
SetValue() is only valid for dynamic attributes.
- Remote writes are accepted only through
InvokeWriteCallback(). If no write callback is installed for a dynamic attribute, the value is still stored and the write succeeds.
Ownership and moves:
- The class is move-only (inherits
MovableOnly) to avoid accidental copies of pointer-backed/static storage and callback state.
Construction:
- Provide a
Uuid plus a properties bitmask; an optional handle can be supplied (otherwise it defaults to 0 until assigned).
- Provide a
Uuid, properties, and initial value buffer for static data.
Setting flags:
- Flags are stored as a
uint16_t bitmask. Use the Properties enum constants and the provided bitwise operators to combine them.
- The
kUuid128 flag is synchronized automatically based on the Uuid when constructing or calling SetProperties().
- Permission bits are not enforced by this class; the stack should gate read/write requests before invoking callbacks.
Callback architecture:
- Read callbacks return
uint16_t: byte count on success, or ATT error code (cast from BleError) on failure. This allows reads to dynamically determine how much data to return.
- Write callbacks return
BleError: type-safe error codes ensure correct error handling without manual conversions. Returns BleError::kSuccess on successful write operations.
- Platform-specific implementations in platform/rpi_pico/ handle BTstack integration; core logic remains platform-independent.
Attribute type helpers:
- Use
Uuid::AttributeType for the standard 16-bit type UUIDs.
- Use
Uuid::Is* helpers when you only have a UUID. This class provides wrappers that accept an Attribute object.
Example:
attr.SetWriteCallback([](uint16_t offset, const uint8_t* data, uint16_t size) {
});
attr.SetReadCallback([](uint16_t offset, uint8_t* buffer, uint16_t buffer_size) {
return bytes_read;
});
ATT attribute wrapper with BTstack-compatible fields.
Definition attribute.hpp:119
@ kRead
Attribute can be read via ATT Read Request.
@ kWrite
Attribute can be written via Write Request (with response).
UUID storage for 16-bit and 128-bit UUIDs.
Definition uuid.hpp:53
@ kSuccess
Generic HCI status and controller errors.
Dynamic attributes:
- If
kDynamic is set, the attribute uses owned storage and optional callbacks rather than a fixed in-DB value.
- When a write callback is installed,
InvokeWriteCallback() calls the callback first. If it succeeds, dynamic_value_ is updated (when data is provided).
Thread safety:
- Not thread-safe. External synchronization required for concurrent access.