|
ELEC-C7222
Libraries for ELEC C7222 Course Work
|
Represents a GATT Characteristic with its declaration, value, and descriptors. More...
#include <characteristic.hpp>


Classes | |
| struct | EventHandler |
| Characteristic event handler structure. More... | |
Public Types | |
Types and Configuration Enums | |
Type definitions and configuration enums for characteristics. | |
| enum class | Properties : uint8_t { kNone = 0x00 , kBroadcast = 0x01 , kRead = 0x02 , kWriteWithoutResponse = 0x04 , kWrite = 0x08 , kNotify = 0x10 , kIndicate = 0x20 , kAuthenticatedSignedWrites = 0x40 , kExtendedProperties = 0x80 } |
| GATT Characteristic Properties as defined in Bluetooth Core Spec. More... | |
| enum class | CCCDProperties : uint16_t { kNone = 0x0000 , kNotifications = 0x0001 , kIndications = 0x0002 } |
| Client Characteristic Configuration Descriptor (CCCD) bit values. More... | |
| enum class | SCCDProperties : uint16_t { kNone = 0x0000 , kBroadcasts = 0x0001 } |
| Server Characteristic Configuration Descriptor (SCCD) bit values. More... | |
| enum class | ExtendedProperties : uint16_t { kNone = 0x0000 , kReliableWrite = 0x0001 , kWritableAuxiliaries = 0x0002 } |
| Characteristic Extended Properties bit values. More... | |
| enum class | SecurityLevel : uint8_t { kNone = 0 , kEncryptionRequired = 1 , kAuthenticationRequired = 2 , kAuthorizationRequired = 3 } |
| Security level requirements for read/write operations. More... | |
| enum class | EventId : uint8_t { kHandleValueIndicationComplete , kAttEventEnd } |
| Event IDs for Characteristic-related ATT events. More... | |
Public Member Functions | |
Core Accessors | |
Accessors for identifiers, handles, and validity checks. | |
| const Uuid & | GetUuid () const |
| Get the UUID of this characteristic. | |
| Properties | GetProperties () const |
| Get the properties of this characteristic. | |
| uint16_t | GetValueHandle () const |
| Get the handle of the Value attribute. | |
| uint16_t | GetDeclarationHandle () const |
| Get the handle of the Declaration attribute. | |
| bool | IsValid () const |
| Check if this characteristic is valid. | |
| bool | IsThisCharacteristic (const Uuid &uuid, uint16_t handle) const |
| Check if this characteristic matches the given UUID and handle. | |
| bool | IsThisCharacteristic (const Uuid &uuid) const |
| Check if this characteristic matches the given UUID. | |
| bool | HasHandle (uint16_t handle) const |
| Check if this characteristic owns the given handle. | |
Capability Checks | |
Helpers to query characteristic capability flags. | |
| bool | HasBroadcast () const |
| Check if characteristic supports broadcasts. | |
| bool | CanRead () const |
| Check if characteristic supports read operations. | |
| bool | CanWriteWithoutResponse () const |
| Check if characteristic supports write without response. | |
| bool | CanWrite () const |
| Check if characteristic supports write operations (with response). | |
| bool | HasNotifications () const |
| Check if characteristic supports notifications. | |
| bool | HasIndications () const |
| Check if characteristic supports indications. | |
| bool | CanSignedWrite () const |
| Check if characteristic supports authenticated signed writes. | |
| bool | HasExtendedPropertiesCapability () const |
| Check if characteristic properties flag has extended properties capability. | |
Security Requirement Checks | |
Helpers to inspect configured security requirements. | |
| bool | ReadHasSecurityRequirement () const |
| Check if characteristic has read permission bits set (requires authorization). Read permission bits 0 and 1 indicate security level requirements. | |
| bool | WriteHasSecurityRequirement () const |
| Check if characteristic has write permission bits set (requires authorization). Write permission bits 0 and 1 indicate security level requirements. | |
| bool | ReadRequiresSC () const |
| Check if characteristic read requires Secure Connections (SC). | |
| bool | WriteRequiresSC () const |
| Check if characteristic write requires Secure Connections (SC). | |
| uint16_t | GetEncryptionKeySize () const |
| Get the required encryption key size for this characteristic. Returns the encryption key size requirement encoded in bits 12-15. | |
| bool | ReadRequiresAuthentication () const |
| Check whether reads require authenticated pairing (MITM). | |
| bool | WriteRequiresAuthentication () const |
| Check whether writes require authenticated pairing (MITM). | |
| bool | ReadRequiresAuthorization () const |
| Check whether reads require application-level authorization. | |
| bool | WriteRequiresAuthorization () const |
| Check whether writes require application-level authorization. | |
| bool | ReadRequiresEncryption () const |
| Check whether reads require at least encrypted link security. | |
| bool | WriteRequiresEncryption () const |
| Check whether writes require at least encrypted link security. | |
| bool | RequiresAuthentication () const |
| Check whether any access requires authentication. | |
| bool | RequiresAuthorization () const |
| Check whether any access requires authorization. | |
| bool | RequiresEncryption () const |
| Check whether any access requires at least encrypted link security. | |
Security Configuration | |
APIs to configure required security levels. | |
| void | SetReadSecurityLevel (SecurityLevel level) |
| Set read security level requirement for this characteristic. | |
| void | SetWriteSecurityLevel (SecurityLevel level) |
| Set write security level requirement for this characteristic. | |
| void | SetReadRequiresSecureConnections (bool required) |
| Set Secure Connections requirement for reads. | |
| void | SetWriteRequiresSecureConnections (bool required) |
| Set Secure Connections requirement for writes. | |
| void | SetEncryptionKeySize (uint8_t key_size) |
| Set minimum encryption key size requirement. | |
| SecurityLevel | GetReadSecurityLevel () const |
| Get current read security level. | |
| SecurityLevel | GetWriteSecurityLevel () const |
| Get current write security level. | |
Permission Evaluation | |
Evaluate access permissions for a given connection state. | |
| bool | IsReadPermitted (bool authorized, bool authenticated) const |
| Check if read is permitted given the connection security state. | |
| bool | IsWritePermitted (bool authorized, bool authenticated) const |
| Check if write is permitted given the connection security state. | |
| bool | Uses128BitUuid () const |
| Check if characteristic has 128-bit UUID. | |
| bool | IsDynamic () const |
| Check if characteristic value is dynamic (can change). | |
Value Access | |
Read the current stored characteristic value. | |
| const uint8_t * | GetValueData () const |
| Get the current value data pointer. For dynamic values, this may change after SetValue() calls. | |
| size_t | GetValueSize () const |
| Get the size of the current value. | |
| std::vector< uint8_t > | GetValueAsVector () const |
| Get the complete value as a vector. | |
Value Updates | |
Update stored values and trigger update flow. | |
| bool | SetValue (const uint8_t *data, size_t size) |
| Set the characteristic value from raw bytes (pointer + size). Only allowed for dynamic characteristics. | |
| bool | SetValue (std::vector< uint8_t > &&data) |
| Set the characteristic value from an rvalue vector (move semantics). Only allowed for dynamic characteristics. | |
| bool | SetValue (const std::vector< uint8_t > &data) |
| Set the characteristic value from an lvalue vector (copy semantics). Only allowed for dynamic characteristics. | |
| template<typename T > | |
| bool | SetValue (const T &value) |
| Set the characteristic value from a typed value (generic template). Converts any trivial type to bytes and stores as the value. Only allowed for dynamic characteristics. | |
Descriptor Management | |
Create and inspect standard and custom descriptors. | |
| Attribute & | EnableCCCD () |
| Enable Client Characteristic Configuration Descriptor (CCCD). Required for characteristics with Notify or Indicate properties. Initializes CCCD with value {0x00, 0x00} (notifications and indications disabled). | |
| bool | HasCCCD () const |
| Check if CCCD descriptor is present. | |
| bool | IsNotificationsEnabled () const |
| Check if notifications are enabled via CCCD. | |
| bool | IsIndicationsEnabled () const |
| Check if indications are enabled via CCCD. | |
| Attribute * | GetCCCD () |
| Get the CCCD descriptor. | |
| const Attribute * | GetCCCD () const |
| Get the CCCD descriptor (const version). | |
| Attribute & | SetCCCDValue (CCCDProperties config) |
| Set CCCD configuration value. Enables or configures notifications and/or indications. Automatically creates CCCD descriptor if not present. | |
| Attribute & | EnableSCCD () |
| Enable Server Characteristic Configuration Descriptor (SCCD). Required for characteristics with Broadcast property. Initializes SCCD with value {0x00, 0x00} (broadcasts disabled). | |
| bool | HasSCCD () const |
| Check if SCCD descriptor is present. | |
| bool | IsBroadcastEnabled () const |
| Check if broadcasts are enabled via SCCD. | |
| Attribute * | GetSCCD () |
| Get the SCCD descriptor. | |
| const Attribute * | GetSCCD () const |
| Get the SCCD descriptor (const version). | |
| Attribute & | SetSCCDValue (SCCDProperties config) |
| Set SCCD configuration value. Enables or disables broadcasts. Automatically creates SCCD descriptor if not present. | |
| Attribute & | EnableExtendedProperties () |
| Enable Characteristic Extended Properties Descriptor. Defines additional characteristic properties beyond the standard properties byte. Initializes with value {0x00, 0x00} (no extended properties). | |
| bool | HasExtendedProperties () const |
| Check if Extended Properties descriptor is present. | |
| Attribute * | GetExtendedProperties () |
| Get the Extended Properties descriptor. | |
| const Attribute * | GetExtendedProperties () const |
| Get the Extended Properties descriptor (const version). | |
| Attribute & | SetExtendedPropertiesValue (ExtendedProperties config) |
| Set Extended Properties configuration value. Configures reliable write and writable auxiliaries. Automatically creates Extended Properties descriptor if not present. | |
| Attribute & | SetUserDescription (const std::string &description) |
| Set the Characteristic User Description. Creates or updates the user-readable description of this characteristic. | |
| const std::string * | SetUserDescriptionText (const std::string &description) |
| Update the user description text if a User Description descriptor exists. | |
| bool | HasUserDescription () const |
| Check if User Description descriptor is present. | |
| Attribute * | GetUserDescription () |
| Get the User Description descriptor. | |
| const std::string & | GetUserDescriptionText () const |
| Get the user description text. | |
| const Attribute * | GetUserDescription () const |
| Get the User Description descriptor (const version). | |
| Attribute & | AddDescriptor (const Uuid &uuid, Attribute::Properties properties, const std::vector< uint8_t > &value, uint16_t handle=0) |
| Add a custom descriptor to this characteristic. Allows extension with application-specific descriptors beyond CCCD and User Description. | |
| size_t | GetDescriptorCount () const |
| Get count of custom descriptors (excluding CCCD and User Description). | |
| Attribute * | GetDescriptor (size_t index) |
| Get a custom descriptor by index. | |
| const Attribute * | GetDescriptor (size_t index) const |
| Get a custom descriptor by index (const version). | |
Attribute Access | |
Access underlying Attribute objects. | |
| Attribute & | GetDeclarationAttribute () |
| Get the Declaration Attribute. The declaration attribute contains properties, value handle, and UUID. | |
| const Attribute & | GetDeclarationAttribute () const |
| Get the Declaration Attribute (const version). | |
| Attribute & | GetValueAttribute () |
| Get the Value Attribute. The value attribute holds the actual characteristic data. | |
| const Attribute & | GetValueAttribute () const |
| Get the Value Attribute (const version). | |
Event Handler Management | |
Register and manage characteristic event handlers. | |
| void | AddEventHandler (EventHandler &handler) |
| Register an event handler for this characteristic. | |
| bool | RemoveEventHandler (const EventHandler &handler) |
| Unregister an event handler from this characteristic. | |
| void | ClearEventHandlers () |
| Clear all registered event handlers for this characteristic. | |
| std::list< EventHandler * > | GetEventHandlers () const |
| Get the list of registered event handlers. | |
Connection Handle Management | |
Manage the active connection handle used for updates. | |
| void | SetConnectionHandle (uint16_t connection_handle) |
| Set the connection handle for this characteristic. | |
| uint16_t | GetConnectionHandle () const |
| Get the current connection handle. | |
Stack Dispatch (Internal) | |
BLE stack entry points reserved for internal use. | |
| virtual BleError | DispatchBleHciPacket (uint8_t packet_type, const uint8_t *packet_data, uint16_t packet_data_size) |
| Dispatch BLE HCI packet to the appropriate event handler. | |
| uint16_t | HandleAttributeRead (uint16_t attribute_handle, uint16_t offset, uint8_t *buffer, uint16_t buffer_size) |
| Attribute read handler for BLE stack callbacks. | |
| BleError | HandleAttributeWrite (uint16_t attribute_handle, uint16_t offset, const uint8_t *data, uint16_t size) |
| Attribute write handler for BLE stack callbacks. | |
Public Member Functions inherited from c7222::MovableOnly | |
| virtual | ~MovableOnly ()=default |
| MovableOnly (MovableOnly &&)=default | |
| MovableOnly & | operator= (MovableOnly &&)=default |
| MovableOnly ()=default | |
Public Member Functions inherited from c7222::NonCopyable | |
| NonCopyable (const NonCopyable &)=delete | |
| NonCopyable & | operator= (const NonCopyable &)=delete |
| NonCopyable (NonCopyable &&)=default | |
| NonCopyable & | operator= (NonCopyable &&)=default |
Protected Member Functions | |
Internal Event Fan-out | |
Internal event dispatch to registered handlers. | |
| BleError | DispatchEvent (EventId event_id, const uint8_t *event_data, uint16_t event_data_size) |
| Dispatch event to registered event handlers. | |
Internal Updates | |
Internal update/notification transport. | |
| virtual BleError | UpdateValue () |
| Update the characteristic value and send notification/indication if enabled. | |
Protected Member Functions inherited from c7222::NonCopyable | |
| NonCopyable ()=default | |
| ~NonCopyable ()=default | |
Friends | |
| std::ostream & | operator<< (std::ostream &os, const Characteristic &characteristic) |
| Stream insertion operator for Characteristic. Outputs the characteristic UUID, properties, security requirements, and descriptors. | |
Construction and Parsing | |
APIs for building or parsing characteristics. | |
| Characteristic (const Uuid &uuid, uint8_t properties, uint16_t declaration_handle, uint16_t value_handle) | |
| Construct a new Characteristic with declaration data. Creates the characteristic with proper declaration attribute. The value handle is typically declaration_handle + 1. | |
| Characteristic (Attribute &&decl_attribute, Attribute &&value_attr, std::list< Attribute > &&descriptor_attrs) | |
| Construct a Characteristic by moving parsed attributes. | |
| Characteristic (Characteristic &&other) noexcept | |
| Move constructor. Transfers ownership of all internal attributes and descriptors. | |
| Characteristic & | operator= (Characteristic &&other) noexcept |
| Move assignment operator. Transfers ownership of all internal attributes and descriptors. | |
| Characteristic ()=delete | |
| Construct a new Characteristic object (deleted). Prevents default construction without parameters. | |
| ~Characteristic () override=default | |
| Destructor. Cleans up all managed attributes and descriptors. | |
| static std::optional< Characteristic > | ParseFromAttributes (std::list< Attribute > &attributes) |
| Parse the first characteristic from a list of attributes. | |
Represents a GATT Characteristic with its declaration, value, and descriptors.
A GATT Characteristic consists of:
The Characteristic Declaration contains:
Characteristics are identified by their UUID and are the primary data containers in a GATT Service.
There are two common ways to create a Characteristic:
ParseFromAttributes() to extract the first characteristic from an ordered attribute list (Declaration, Value, then Descriptors). The extracted attributes are removed from the list and moved into the new Characteristic; no attribute rebuilding is performed. Callbacks are not copied.The class provides event callbacks via EventHandlers. These are invoked when:
OnRead, OnWrite).OnConfirmationComplete), which is driven by HCI events.The application must:
AddEventHandler().DispatchBleHciPacket() so indication completion and flow control (ATT_EVENT_CAN_SEND_NOW) are processed.SetConnectionHandle() to allow notifications/indications to be transmitted when values update.This class treats the Characteristic User Description descriptor as a read-only, application-controlled string. Design principles:
user_description_text_ and served directly by the read handler.SetUserDescription() creates the descriptor (if needed) and updates the stored text; SetUserDescriptionText() updates the text only when a descriptor already exists.BTstack note: BTstack's .gatt files do not allow setting the User Description text for a characteristic. The descriptor can be declared (0x2901), but its contents must be provided by the application at runtime (e.g., via SetUserDescription() / SetUserDescriptionText()).
Characteristic emits debug prints for value reads/writes and CCCD/SCCD updates when the compile definition C7222_BLE_DEBUG is enabled.
In this project, you can enable it via CMake:
-DC7222_BLE_DEBUG=ONOn the Pico W BLE stack, the GATT database is compiled into a binary Attribute DB (typically att_db.h/att_db.c). The AttributeServer parses that binary blob into Attribute objects. You can then call ParseFromAttributes() to peel one characteristic at a time from the ordered list.
Important implications:
Attribute/Characteristic.This implementation mirrors the Bluetooth Core Spec descriptor types and chooses dynamic vs static storage based on whether the value must change at runtime or be written by a client.
Notify or Indicate is set in the characteristic properties (Vol 3, Part G, 3.3.3.3).EnableCCCD() or SetCCCDValue(); initial value is {0x00, 0x00}.kRead | kWrite | kDynamic.Broadcast is set in the characteristic properties (Vol 3, Part G, 3.3.3.4).EnableSCCD() or SetSCCDValue(); initial value is {0x00, 0x00}.kRead | kWrite | kDynamic.ExtendedProperties is set (Vol 3, Part G, 3.3.3.1).EnableExtendedProperties() or SetExtendedPropertiesValue().kRead only (read-only metadata).SetUserDescription() or when AddDescriptor() sees UUID 0x2901.kRead only in this implementation.AddDescriptor().Attribute::Properties::kDynamic is set; otherwise values are stored as static data.The value attribute is the primary data payload for the characteristic. This implementation uses internal read/write callbacks by default:
HandleValueRead().OnRead handlers fire first, giving the app a chance to call SetValue() (dynamic only) to refresh data.HandleValueWrite().OnWrite handlers are called after the value is stored.SetValue() to update the stored value, then call UpdateValue() to send notifications or indications if enabled.Important: if the application replaces the value attribute callbacks via SetReadCallback() or SetWriteCallback(), the default HandleValueRead() and HandleValueWrite() are bypassed. In that case, EventHandlers are not invoked automatically and the application is responsible for storage and side effects.
This class now provides higher-level security query helpers that map directly to the configured SecurityLevel bits on the value attribute:
ReadRequiresAuthentication(), WriteRequiresAuthentication(), RequiresAuthentication()ReadRequiresEncryption(), WriteRequiresEncryption(), RequiresEncryption()ReadRequiresAuthorization(), WriteRequiresAuthorization(), RequiresAuthorization()These helpers are intended to support service- and server-level security planning (for example, deciding whether a SecurityManager must be enabled) before connections are established.
CCCD/SCCD writes are validated against the characteristic's security requirements in HandleCccdWrite() / HandleSccdWrite(). This ensures that clients cannot enable notifications/indications or broadcasts unless the active link meets the required security level (encryption, authentication, or authorization).
The following methods exist to integrate with the BLE stack and platform glue. They are not part of the public application API and should be considered reserved for internal use:
DispatchBleHciPacket() (HCI event dispatch/flow control)HandleAttributeRead() / HandleAttributeWrite() (ATT read/write handlers)DispatchEvent() (internal event fan-out)UpdateValue() (platform transport of notifications/indications)HandleCccdWrite() / HandleSccdWrite() (descriptor write handling)HandleValueRead() / HandleValueWrite() (value attribute handlers)
|
strong |
Client Characteristic Configuration Descriptor (CCCD) bit values.
CCCD allows clients to configure notifications and indications for a characteristic.
| Enumerator | |
|---|---|
| kNone | Neither notifications nor indications enabled. |
| kNotifications | Notifications enabled. |
| kIndications | Indications enabled. |
|
strong |
|
strong |
Characteristic Extended Properties bit values.
Extended Properties descriptor defines additional characteristic properties.
| Enumerator | |
|---|---|
| kNone | No extended properties. |
| kReliableWrite | Reliable Write enabled. |
| kWritableAuxiliaries | Writable Auxiliaries enabled. |
|
strong |
GATT Characteristic Properties as defined in Bluetooth Core Spec.
These properties appear in the first byte of the Characteristic Declaration. They define which operations are permitted on the characteristic value.
| Enumerator | |
|---|---|
| kNone | No properties set. |
| kBroadcast | Characteristic supports broadcast. |
| kRead | Characteristic value can be read. |
| kWriteWithoutResponse | Characteristic value can be written without response. |
| kWrite | Characteristic value can be written with response. |
| kNotify | Characteristic supports notifications. |
| kIndicate | Characteristic supports indications. |
| kAuthenticatedSignedWrites | Characteristic supports authenticated signed writes. |
| kExtendedProperties | Characteristic has extended properties descriptor. |
|
strong |
Server Characteristic Configuration Descriptor (SCCD) bit values.
SCCD allows clients to configure broadcasts for a characteristic.
| Enumerator | |
|---|---|
| kNone | Broadcasts disabled. |
| kBroadcasts | Broadcasts enabled. |
|
strong |
Security level requirements for read/write operations.
These levels define encryption and authentication requirements for accessing the characteristic value. The 2-bit encoding (Bit0 and Bit1) maps to BTstack's ATT_PROPERTY_READ/WRITE_PERMISSION_BIT_0 and BIT_1.
Security levels are enforced by the BLE stack and determine when a client can successfully read or write the characteristic.
|
explicit |
Construct a new Characteristic with declaration data. Creates the characteristic with proper declaration attribute. The value handle is typically declaration_handle + 1.
| uuid | The UUID identifying this characteristic |
| properties | Characteristic properties bitfield (combination of Properties enum flags) |
| declaration_handle | Handle of the Declaration attribute |
| value_handle | Handle of the Value attribute (typically declaration_handle + 1) |
|
explicit |
Construct a Characteristic by moving parsed attributes.
This constructor takes ownership of the declaration/value/descriptor attributes produced during parsing and avoids rebuilding them. Handles are preserved from the moved attributes.
| decl_attribute | Characteristic Declaration attribute (moved) |
| value_attr | Value attribute (moved) |
| descriptor_attrs | Descriptor attributes (moved) |
|
noexcept |
Move constructor. Transfers ownership of all internal attributes and descriptors.
|
delete |
Construct a new Characteristic object (deleted). Prevents default construction without parameters.
|
overridedefault |
Destructor. Cleans up all managed attributes and descriptors.
| Attribute & c7222::Characteristic::AddDescriptor | ( | const Uuid & | uuid, |
| Attribute::Properties | properties, | ||
| const std::vector< uint8_t > & | value, | ||
| uint16_t | handle = 0 |
||
| ) |
Add a custom descriptor to this characteristic. Allows extension with application-specific descriptors beyond CCCD and User Description.
| uuid | UUID of the descriptor |
| properties | Descriptor properties (typically Read and/or Write) |
| value | Initial value of the descriptor |
| handle | Optional handle for the descriptor (used in DB) |
| void c7222::Characteristic::AddEventHandler | ( | EventHandler & | handler | ) |
Register an event handler for this characteristic.
The handler is stored as a pointer; it must outlive the Characteristic instance. Multiple handlers can be registered and will be called in the order they were added.
| handler | Reference to the EventHandlers structure to register |

|
inline |
Check if characteristic supports read operations.
|
inline |
Check if characteristic supports authenticated signed writes.
|
inline |
Check if characteristic supports write operations (with response).
|
inline |
Check if characteristic supports write without response.
| void c7222::Characteristic::ClearEventHandlers | ( | ) |
Clear all registered event handlers for this characteristic.
|
virtual |
Dispatch BLE HCI packet to the appropriate event handler.
This must be fed HCI events so that indication completion and ATT_EVENT_CAN_SEND_NOW flow control are handled.
| packet_type | The type of the HCI packet |
| packet_data | Pointer to the packet data |
| packet_data_size | Size of the packet data |
|
protected |
Dispatch event to registered event handlers.
| event_id | The event identifier |
| event_data | Pointer to the event data |
| event_data_size | Size of the event data |
| Attribute & c7222::Characteristic::EnableCCCD | ( | ) |
Enable Client Characteristic Configuration Descriptor (CCCD). Required for characteristics with Notify or Indicate properties. Initializes CCCD with value {0x00, 0x00} (notifications and indications disabled).
| Attribute & c7222::Characteristic::EnableExtendedProperties | ( | ) |
Enable Characteristic Extended Properties Descriptor. Defines additional characteristic properties beyond the standard properties byte. Initializes with value {0x00, 0x00} (no extended properties).
| Attribute & c7222::Characteristic::EnableSCCD | ( | ) |
Enable Server Characteristic Configuration Descriptor (SCCD). Required for characteristics with Broadcast property. Initializes SCCD with value {0x00, 0x00} (broadcasts disabled).
|
inline |
Get the CCCD descriptor.
|
inline |
Get the CCCD descriptor (const version).
|
inline |
Get the current connection handle.
|
inline |
|
inline |
|
inline |
Get the handle of the Declaration attribute.

| Attribute * c7222::Characteristic::GetDescriptor | ( | size_t | index | ) |
Get a custom descriptor by index.
| index | Index of the descriptor (0 to GetDescriptorCount()-1) |
| const Attribute * c7222::Characteristic::GetDescriptor | ( | size_t | index | ) | const |
Get a custom descriptor by index (const version).
| index | Index of the descriptor (0 to GetDescriptorCount()-1) |
|
inline |
Get count of custom descriptors (excluding CCCD and User Description).
|
inline |
Get the required encryption key size for this characteristic. Returns the encryption key size requirement encoded in bits 12-15.

|
inline |
Get the list of registered event handlers.
|
inline |
Get the Extended Properties descriptor.
|
inline |
Get the Extended Properties descriptor (const version).
|
inline |
Get the properties of this characteristic.
| SecurityLevel c7222::Characteristic::GetReadSecurityLevel | ( | ) | const |
Get current read security level.
|
inline |
Get the SCCD descriptor.
|
inline |
Get the SCCD descriptor (const version).
|
inline |
Get the User Description descriptor.
|
inline |
Get the User Description descriptor (const version).
|
inline |
Get the user description text.
This returns the current user description text. If the User Description descriptor is not present, it returns an empty string reference.

|
inline |
Get the UUID of this characteristic.
| std::vector< uint8_t > c7222::Characteristic::GetValueAsVector | ( | ) | const |
Get the complete value as a vector.
|
inline |
|
inline |
| const uint8_t * c7222::Characteristic::GetValueData | ( | ) | const |
Get the current value data pointer. For dynamic values, this may change after SetValue() calls.
|
inline |
Get the handle of the Value attribute.

| size_t c7222::Characteristic::GetValueSize | ( | ) | const |
Get the size of the current value.
| SecurityLevel c7222::Characteristic::GetWriteSecurityLevel | ( | ) | const |
Get current write security level.
| uint16_t c7222::Characteristic::HandleAttributeRead | ( | uint16_t | attribute_handle, |
| uint16_t | offset, | ||
| uint8_t * | buffer, | ||
| uint16_t | buffer_size | ||
| ) |
Attribute read handler for BLE stack callbacks.
| BleError c7222::Characteristic::HandleAttributeWrite | ( | uint16_t | attribute_handle, |
| uint16_t | offset, | ||
| const uint8_t * | data, | ||
| uint16_t | size | ||
| ) |
Attribute write handler for BLE stack callbacks.
|
inline |
Check if characteristic supports broadcasts.
|
inline |
Check if CCCD descriptor is present.
|
inline |
Check if Extended Properties descriptor is present.
|
inline |
Check if characteristic properties flag has extended properties capability.
| bool c7222::Characteristic::HasHandle | ( | uint16_t | handle | ) | const |
Check if this characteristic owns the given handle.
| handle | Attribute handle (declaration or value) |
|
inline |
Check if characteristic supports indications.
|
inline |
Check if characteristic supports notifications.
|
inline |
Check if SCCD descriptor is present.
|
inline |
Check if User Description descriptor is present.

| bool c7222::Characteristic::IsBroadcastEnabled | ( | ) | const |
Check if broadcasts are enabled via SCCD.
|
inline |
Check if characteristic value is dynamic (can change).

| bool c7222::Characteristic::IsIndicationsEnabled | ( | ) | const |
Check if indications are enabled via CCCD.
| bool c7222::Characteristic::IsNotificationsEnabled | ( | ) | const |
Check if notifications are enabled via CCCD.
| bool c7222::Characteristic::IsReadPermitted | ( | bool | authorized, |
| bool | authenticated | ||
| ) | const |
Check if read is permitted given the connection security state.
Evaluates whether a client with the given security state is allowed to read this characteristic based on the configured read security level and Secure Connections requirement.
| authorized | true if client is authorized (passed app-level authorization) |
| authenticated | true if client has authenticated pairing |
| bool c7222::Characteristic::IsThisCharacteristic | ( | const Uuid & | uuid | ) | const |
Check if this characteristic matches the given UUID.
| uuid | UUID to compare |
| bool c7222::Characteristic::IsThisCharacteristic | ( | const Uuid & | uuid, |
| uint16_t | handle | ||
| ) | const |
Check if this characteristic matches the given UUID and handle.
| uuid | UUID to compare |
| handle | Attribute handle (declaration or value) |
| bool c7222::Characteristic::IsValid | ( | ) | const |
Check if this characteristic is valid.
| bool c7222::Characteristic::IsWritePermitted | ( | bool | authorized, |
| bool | authenticated | ||
| ) | const |
Check if write is permitted given the connection security state.
Evaluates whether a client with the given security state is allowed to write this characteristic based on the configured write security level and Secure Connections requirement.
| authorized | true if client is authorized (passed app-level authorization) |
| authenticated | true if client has authenticated pairing |
|
noexcept |
Move assignment operator. Transfers ownership of all internal attributes and descriptors.
|
static |
Parse the first characteristic from a list of attributes.
This function scans the attribute list for the first Characteristic Declaration attribute, then groups the following attributes (value and descriptors) into a single Characteristic.
Implementation details:
Assumptions:
| attributes | Attribute list to parse; the extracted attributes are removed |
|
inline |
Check if characteristic has read permission bits set (requires authorization). Read permission bits 0 and 1 indicate security level requirements.

| bool c7222::Characteristic::ReadRequiresAuthentication | ( | ) | const |
Check whether reads require authenticated pairing (MITM).
This returns true when the configured read security level is kAuthenticationRequired or kAuthorizationRequired.
| bool c7222::Characteristic::ReadRequiresAuthorization | ( | ) | const |
Check whether reads require application-level authorization.
Authorization is the highest level and implies authentication.
| bool c7222::Characteristic::ReadRequiresEncryption | ( | ) | const |
Check whether reads require at least encrypted link security.
Returns true if the read security level is kEncryptionRequired or higher.
|
inline |
Check if characteristic read requires Secure Connections (SC).

| bool c7222::Characteristic::RemoveEventHandler | ( | const EventHandler & | handler | ) |
Unregister an event handler from this characteristic.
| handler | Reference to the EventHandlers structure to unregister |
| bool c7222::Characteristic::RequiresAuthentication | ( | ) | const |
Check whether any access requires authentication.
Returns true if either read or write requires authentication.
| bool c7222::Characteristic::RequiresAuthorization | ( | ) | const |
Check whether any access requires authorization.
Returns true if either read or write requires authorization.
| bool c7222::Characteristic::RequiresEncryption | ( | ) | const |
Check whether any access requires at least encrypted link security.
| Attribute & c7222::Characteristic::SetCCCDValue | ( | CCCDProperties | config | ) |
Set CCCD configuration value. Enables or configures notifications and/or indications. Automatically creates CCCD descriptor if not present.
| config | CCCD configuration flags |
|
inline |
Set the connection handle for this characteristic.
The connection handle is set when a device connects and the characteristic's security requirements are satisfied. Used by UpdateValue to send notifications/indications.
| connection_handle | The connection handle (0 is invalid/disconnected) |
| void c7222::Characteristic::SetEncryptionKeySize | ( | uint8_t | key_size | ) |
Set minimum encryption key size requirement.
Configures the minimum encryption key size (in bytes) that clients must use. Valid range is 7-16 bytes per Bluetooth specification. Sets bits 12-15 of the attribute properties (ATT_PROPERTY_ENCRYPTION_KEY_SIZE_MASK).
| key_size | Minimum key size in bytes (7-16), or 0 for no requirement |
| Attribute & c7222::Characteristic::SetExtendedPropertiesValue | ( | ExtendedProperties | config | ) |
Set Extended Properties configuration value. Configures reliable write and writable auxiliaries. Automatically creates Extended Properties descriptor if not present.
| config | Extended properties flags |
| void c7222::Characteristic::SetReadRequiresSecureConnections | ( | bool | required | ) |
Set Secure Connections requirement for reads.
When enabled, reads require LE Secure Connections pairing (Bluetooth 4.2+). This provides enhanced security with ECDH key agreement. Sets ATT_PROPERTY_READ_PERMISSION_SC flag.
| required | true to require Secure Connections, false to allow legacy pairing |
| void c7222::Characteristic::SetReadSecurityLevel | ( | SecurityLevel | level | ) |
Set read security level requirement for this characteristic.
Configures the security level that clients must meet to read this characteristic. This sets the appropriate ATT_PROPERTY_READ_PERMISSION_BIT_0 and BIT_1 flags on the value attribute.
| level | Security level (None, Encryption, Authentication, or Authorization) |
| Attribute & c7222::Characteristic::SetSCCDValue | ( | SCCDProperties | config | ) |
Set SCCD configuration value. Enables or disables broadcasts. Automatically creates SCCD descriptor if not present.
| config | SCCD configuration flags |
| Attribute & c7222::Characteristic::SetUserDescription | ( | const std::string & | description | ) |
Set the Characteristic User Description. Creates or updates the user-readable description of this characteristic.
| description | Human-readable description string |

| const std::string * c7222::Characteristic::SetUserDescriptionText | ( | const std::string & | description | ) |
Update the user description text if a User Description descriptor exists.
| description | Human-readable description string |
This does not create the descriptor. It is intended for cases where the 0x2901 descriptor already exists (e.g., parsed from the ATT DB) and the application wants to update the text at runtime. The descriptor is forced read-only and served via the internal read handler.
| bool c7222::Characteristic::SetValue | ( | const std::vector< uint8_t > & | data | ) |
Set the characteristic value from an lvalue vector (copy semantics). Only allowed for dynamic characteristics.
| data | Const reference to vector (copied into storage) |
|
inline |
Set the characteristic value from a typed value (generic template). Converts any trivial type to bytes and stores as the value. Only allowed for dynamic characteristics.
| T | Must be a trivial type (primitive types, arrays, small structs) |
| value | The value to store |
SetValue<uint16_t>(0x1234) stores as bytes {0x34, 0x12} (little-endian). 
| bool c7222::Characteristic::SetValue | ( | const uint8_t * | data, |
| size_t | size | ||
| ) |
Set the characteristic value from raw bytes (pointer + size). Only allowed for dynamic characteristics.
| data | Pointer to value data (copied into storage) |
| size | Size of the data in bytes |

| bool c7222::Characteristic::SetValue | ( | std::vector< uint8_t > && | data | ) |
Set the characteristic value from an rvalue vector (move semantics). Only allowed for dynamic characteristics.
| data | Rvalue reference to vector (moved into storage) |
| void c7222::Characteristic::SetWriteRequiresSecureConnections | ( | bool | required | ) |
Set Secure Connections requirement for writes.
When enabled, writes require LE Secure Connections pairing (Bluetooth 4.2+). This provides enhanced security with ECDH key agreement. Sets ATT_PROPERTY_WRITE_PERMISSION_SC flag.
| required | true to require Secure Connections, false to allow legacy pairing |
| void c7222::Characteristic::SetWriteSecurityLevel | ( | SecurityLevel | level | ) |
Set write security level requirement for this characteristic.
Configures the security level that clients must meet to write this characteristic. This sets the appropriate ATT_PROPERTY_WRITE_PERMISSION_BIT_0 and BIT_1 flags on the value attribute.
| level | Security level (None, Encryption, Authentication, or Authorization) |
|
protectedvirtual |
Update the characteristic value and send notification/indication if enabled.
This is called internally by SetValue functions to handle platform-specific transmission logic. The function checks CCCD configuration and sends the appropriate update to the connected client based on enabled notifications/indications.
Logic:
|
inline |
Check if characteristic has 128-bit UUID.

|
inline |
Check if characteristic has write permission bits set (requires authorization). Write permission bits 0 and 1 indicate security level requirements.

| bool c7222::Characteristic::WriteRequiresAuthentication | ( | ) | const |
Check whether writes require authenticated pairing (MITM).
This returns true when the configured write security level is kAuthenticationRequired or kAuthorizationRequired.
| bool c7222::Characteristic::WriteRequiresAuthorization | ( | ) | const |
Check whether writes require application-level authorization.
Authorization is the highest level and implies authentication.
| bool c7222::Characteristic::WriteRequiresEncryption | ( | ) | const |
Check whether writes require at least encrypted link security.
Returns true if the write security level is kEncryptionRequired or higher.
|
inline |
Check if characteristic write requires Secure Connections (SC).

|
friend |
Stream insertion operator for Characteristic. Outputs the characteristic UUID, properties, security requirements, and descriptors.
| os | Output stream |
| characteristic | The characteristic to output |