Mistake on this page?
Report an issue in GitHub or email us
Public Types | Public Member Functions | Static Public Attributes
GattAttribute Class Reference

Representation of a GattServer attribute. More...

#include <GattAttribute.h>

Public Types

typedef ble::attribute_handle_t Handle_t
 Representation of an attribute handle. More...
 

Public Member Functions

 GattAttribute (const UUID &uuid, uint8_t *valuePtr=NULL, uint16_t len=0, uint16_t maxLen=0, bool hasVariableLen=true)
 Construct an attribute. More...
 
Handle_t getHandle (void) const
 Get the attribute's handle in the ATT table. More...
 
const UUIDgetUUID (void) const
 Get the UUID of the attribute. More...
 
uint16_t getLength (void) const
 Get the current length of the attribute value. More...
 
uint16_t getMaxLength (void) const
 Get the maximum length of the attribute value. More...
 
uint16_t * getLengthPtr (void)
 Get a pointer to the current length of the attribute value. More...
 
void setHandle (Handle_t id)
 Set the attribute handle. More...
 
uint8_t * getValuePtr (void)
 Get a pointer to the attribute value. More...
 
bool hasVariableLength (void) const
 Check whether the length of the attribute's value can change throughout time. More...
 
void allowRead (bool allow_read)
 Allow or disallow read operation from a client. More...
 
bool isReadAllowed (void) const
 Indicate if a client is allowed to read the attribute. More...
 
void setReadSecurityRequirement (Security_t requirement)
 Set the security requirements of the read operations. More...
 
Security_t getReadSecurityRequirement () const
 Return the security level required by read operations. More...
 
void allowWrite (bool allow_write)
 Allow or disallow write operation from a client. More...
 
bool isWriteAllowed (void) const
 Indicate if a client is allowed to write the attribute. More...
 
void setWriteSecurityRequirement (Security_t requirement)
 Set the security requirements of the write operations. More...
 
Security_t getWriteSecurityRequirement () const
 Return the security level required by write operations. More...
 

Static Public Attributes

static const Handle_t INVALID_HANDLE = 0x0000
 Invalid attribute handle. More...
 

Detailed Description

Representation of a GattServer attribute.

Attributes are the building block of GATT servers: services are attributes, characteristics are groups of attributes and characteristic descriptors are attributes, too.

Typed values

Attributes are typed values composed of a type and its associated value. The attribute type identifies the attribute purpose. A UUID read by the client during the discovery of the GATT server models the attribute type. The value of the attribute is an array of bytes; its length may be fixed or variable.

As an example, a primary service is declared by an attribute with the type 0x2800, and the value of the attribute is the UUID of the service.

Attribute Access

The GATT server is an array of attributes in which a unique index identifies each of the attributes within the array. That index is called the attribute handle, and clients use it to access to attributes within the server.

Note
Attributes do not contain information related to their permissions, grouping or semantic. Higher level specifications define these concepts.

Definition at line 58 of file GattAttribute.h.

Member Typedef Documentation

Representation of an attribute handle.

Each attribute in a GattServer has a unique handle that clients can use to identify the attribute. The underlying BLE stack usually generates and assigns handles to attributes.

Definition at line 67 of file GattAttribute.h.

Constructor & Destructor Documentation

GattAttribute ( const UUID uuid,
uint8_t *  valuePtr = NULL,
uint16_t  len = 0,
uint16_t  maxLen = 0,
bool  hasVariableLen = true 
)

Construct an attribute.

Application code uses attributes to model characteristic descriptors and characteristics values.

Parameters
[in]uuidThe type of the attribute.
[in]valuePtrPointer to the memory buffer, which contains the initial value of the attribute. The constructor does not make a copy of the attribute buffer; as a consequence, the memory buffer must remain valid during the lifetime of the attribute.
[in]lenThe length in bytes of this attribute's value.
[in]maxLenThe length in bytes of the memory buffer containing the attribute value. It must be greater than or equal to len.
[in]hasVariableLenFlag that indicates whether the attribute's value length can change throughout time.
Example
// declare a value of 2 bytes within a 10 bytes buffer
const uint8_t attribute_value[10] = { 10, 50 };
0x2A19, // attribute type
attribute_value,
2, // length of the current value
sizeof(attribute_value), // length of the buffer containing the value
true // variable length
);
Note
By default, read and write operations are allowed and does not require any security.

Definition at line 112 of file GattAttribute.h.

Member Function Documentation

void allowRead ( bool  allow_read)

Allow or disallow read operation from a client.

Parameters
allow_readRead is allowed if true.

Definition at line 226 of file GattAttribute.h.

void allowWrite ( bool  allow_write)

Allow or disallow write operation from a client.

Parameters
allow_writeWrite is allowed if true.

Definition at line 262 of file GattAttribute.h.

Handle_t getHandle ( void  ) const

Get the attribute's handle in the ATT table.

Note
The GattServer sets the attribute's handle when services are inserted.
Returns
The attribute's handle.

Definition at line 139 of file GattAttribute.h.

uint16_t getLength ( void  ) const

Get the current length of the attribute value.

Returns
The current length of the attribute value.

Definition at line 161 of file GattAttribute.h.

uint16_t* getLengthPtr ( void  )

Get a pointer to the current length of the attribute value.

Attention
note Do not use this function.
Returns
A pointer to the current length of the attribute value.

Definition at line 183 of file GattAttribute.h.

uint16_t getMaxLength ( void  ) const

Get the maximum length of the attribute value.

The maximum length of the attribute value.

Definition at line 171 of file GattAttribute.h.

Security_t getReadSecurityRequirement ( ) const

Return the security level required by read operations.

Returns
The security level of the read operations.

Definition at line 253 of file GattAttribute.h.

const UUID& getUUID ( void  ) const

Get the UUID of the attribute.

The UUID identifies the type of the attribute.

Returns
The attribute.

Definition at line 151 of file GattAttribute.h.

uint8_t* getValuePtr ( void  )

Get a pointer to the attribute value.

Returns
A pointer to the attribute value.

Definition at line 206 of file GattAttribute.h.

Security_t getWriteSecurityRequirement ( ) const

Return the security level required by write operations.

Returns
The security level of the write operations.

Definition at line 289 of file GattAttribute.h.

bool hasVariableLength ( void  ) const

Check whether the length of the attribute's value can change throughout time.

Returns
true if the attribute value has a variable length and false otherwise.

Definition at line 217 of file GattAttribute.h.

bool isReadAllowed ( void  ) const

Indicate if a client is allowed to read the attribute.

Returns
true if a client is allowed to read the attribute.

Definition at line 235 of file GattAttribute.h.

bool isWriteAllowed ( void  ) const

Indicate if a client is allowed to write the attribute.

Returns
true if a client is allowed to write the attribute.

Definition at line 271 of file GattAttribute.h.

void setHandle ( Handle_t  id)

Set the attribute handle.

Attention
The GattServer uses this function internally. Application code must not use it.
Parameters
[in]idThe new attribute handle.

Definition at line 196 of file GattAttribute.h.

void setReadSecurityRequirement ( Security_t  requirement)

Set the security requirements of the read operations.

Parameters
requirementThe security level required by the read operations.

Definition at line 244 of file GattAttribute.h.

void setWriteSecurityRequirement ( Security_t  requirement)

Set the security requirements of the write operations.

Parameters
requirementThe security level required by the write operations.

Definition at line 280 of file GattAttribute.h.

Field Documentation

const Handle_t INVALID_HANDLE = 0x0000
static

Invalid attribute handle.

Definition at line 72 of file GattAttribute.h.

Important Information for this Arm website

This site uses cookies to store information on your computer. By continuing to use our site, you consent to our cookies. If you are not happy with the use of these cookies, please review our Cookie Policy to learn how they can be disabled. By disabling cookies, some features of the site will not work.