GATT Client#

GATT Client.

Modules

sl_bt_evt_gatt_mtu_exchanged

Indicates that an ATT_MTU exchange procedure is completed.

sl_bt_evt_gatt_service

Indicate that a GATT service in the remote GATT database was discovered.

sl_bt_evt_gatt_characteristic

Indicates that a GATT characteristic in the remote GATT database was discovered.

sl_bt_evt_gatt_descriptor

Indicates that a GATT characteristic descriptor in the remote GATT database was discovered.

sl_bt_evt_gatt_characteristic_value

Indicates that the value of one or several characteristics in the remote GATT server was received.

sl_bt_evt_gatt_descriptor_value

Indicates that the value of a descriptor in the remote GATT server was received.

sl_bt_evt_gatt_procedure_completed

Indicates that the current GATT procedure was completed successfully or that it failed with an error.

Enumerations

enum

sl_bt_gatt_att_opcode_t { sl_bt_gatt_read_by_type_request = 0x8, sl_bt_gatt_read_by_type_response = 0x9, sl_bt_gatt_read_request = 0xa, sl_bt_gatt_read_response = 0xb, sl_bt_gatt_read_blob_request = 0xc, sl_bt_gatt_read_blob_response = 0xd, sl_bt_gatt_read_multiple_request = 0xe, sl_bt_gatt_read_multiple_response = 0xf, sl_bt_gatt_write_request = 0x12, sl_bt_gatt_write_response = 0x13,sl_bt_gatt_write_command = 0x52, sl_bt_gatt_prepare_write_request = 0x16, sl_bt_gatt_prepare_write_response = 0x17,sl_bt_gatt_execute_write_request = 0x18, sl_bt_gatt_execute_write_response = 0x19, sl_bt_gatt_handle_value_notification = 0x1b, sl_bt_gatt_handle_value_indication = 0x1d}

Attribute Protocol Opcode.

enum

sl_bt_gatt_client_config_flag_t { sl_bt_gatt_disable = 0x0, sl_bt_gatt_notification = 0x1, sl_bt_gatt_indication = 0x2 }

Characteristic Client Configuration Flag.

enum

sl_bt_gatt_execute_write_flag_t { sl_bt_gatt_cancel = 0x0, sl_bt_gatt_commit = 0x1}

Execute Write Flag.

Functions

sl_status_t

sl_bt_gatt_set_max_mtu (uint16_t max_mtu, uint16_t *max_mtu_out)

sl_status_t

sl_bt_gatt_discover_primary_services (uint8_t connection)

sl_status_t

sl_bt_gatt_discover_primary_services_by_uuid (uint8_t connection, size_t uuid_len, const uint8_t *uuid)

sl_status_t

sl_bt_gatt_find_included_services (uint8_t connection, uint32_t service)

sl_status_t

sl_bt_gatt_discover_characteristics (uint8_t connection, uint32_t service)

sl_status_t

sl_bt_gatt_discover_characteristics_by_uuid (uint8_t connection, uint32_t service, size_t uuid_len, const uint8_t *uuid)

sl_status_t

sl_bt_gatt_discover_descriptors (uint8_t connection, uint16_t characteristic)

sl_status_t

sl_bt_gatt_set_characteristic_notification (uint8_t connection, uint16_t characteristic, uint8_t flags)

sl_status_t

sl_bt_gatt_send_characteristic_confirmation (uint8_t connection)

sl_status_t

sl_bt_gatt_read_characteristic_value (uint8_t connection, uint16_t characteristic)

sl_status_t

sl_bt_gatt_read_characteristic_value_from_offset (uint8_t connection, uint16_t characteristic, uint16_t offset, uint16_t maxlen)

sl_status_t

sl_bt_gatt_read_multiple_characteristic_values (uint8_t connection, size_t characteristic_list_len, const uint8_t *characteristic_list)

sl_status_t

sl_bt_gatt_read_characteristic_value_by_uuid (uint8_t connection, uint32_t service, size_t uuid_len, const uint8_t *uuid)

sl_status_t

sl_bt_gatt_write_characteristic_value (uint8_t connection, uint16_t characteristic, size_t value_len, const uint8_t *value)

sl_status_t

sl_bt_gatt_write_characteristic_value_without_response (uint8_t connection, uint16_t characteristic, size_t value_len, const uint8_t *value, uint16_t *sent_len)

sl_status_t

sl_bt_gatt_prepare_characteristic_value_write (uint8_t connection, uint16_t characteristic, uint16_t offset, size_t value_len, const uint8_t *value, uint16_t *sent_len)

sl_status_t

sl_bt_gatt_prepare_characteristic_value_reliable_write (uint8_t connection, uint16_t characteristic, uint16_t offset, size_t value_len, const uint8_t *value, uint16_t *sent_len)

sl_status_t

sl_bt_gatt_execute_characteristic_value_write (uint8_t connection, uint8_t flags)

sl_status_t

sl_bt_gatt_read_descriptor_value (uint8_t connection, uint16_t descriptor)

sl_status_t

sl_bt_gatt_write_descriptor_value (uint8_t connection, uint16_t descriptor, size_t value_len, const uint8_t *value)

Detailed Description#

GATT Client.

The commands and events in this class are used to browse and manage attributes in a remote GATT server.

Enumeration Type Documentation#

sl_bt_gatt_att_opcode_t#

enum sl_bt_gatt_att_opcode_t

Attribute Protocol Opcode.

Enumerator

sl_bt_gatt_read_by_type_request

(0x8) Read by type request

sl_bt_gatt_read_by_type_response

(0x9) Read by type response

sl_bt_gatt_read_request

(0xa) Read request

sl_bt_gatt_read_response

(0xb) Read response

sl_bt_gatt_read_blob_request

(0xc) Read blob request

sl_bt_gatt_read_blob_response

(0xd) Read blob response

sl_bt_gatt_read_multiple_request

(0xe) Read multiple request

sl_bt_gatt_read_multiple_response

(0xf) Read multiple response

sl_bt_gatt_write_request

(0x12) Write request

sl_bt_gatt_write_response

(0x13) Write response

sl_bt_gatt_write_command

(0x52) Write command

sl_bt_gatt_prepare_write_request

(0x16) Prepare write request

sl_bt_gatt_prepare_write_response

(0x17) Prepare write response

sl_bt_gatt_execute_write_request

(0x18) Execute write request

sl_bt_gatt_execute_write_response

(0x19) Execute write response

sl_bt_gatt_handle_value_notification

(0x1b) Notification

sl_bt_gatt_handle_value_indication

(0x1d) Indication


sl_bt_gatt_client_config_flag_t#

enum sl_bt_gatt_client_config_flag_t

Characteristic Client Configuration Flag.

Enumerator

sl_bt_gatt_disable

(0x0) Disable notifications and indications

sl_bt_gatt_notification

(0x1) Notification

sl_bt_gatt_indication

(0x2) Indication


sl_bt_gatt_execute_write_flag_t#

enum sl_bt_gatt_execute_write_flag_t

Execute Write Flag.

Enumerator

sl_bt_gatt_cancel

(0x0) Cancel all queued writes

sl_bt_gatt_commit

(0x1) Commit all queued writes

Function Documentation#

sl_bt_gatt_set_max_mtu()#

sl_status_t sl_bt_gatt_set_max_mtu

(

uint16_t

max_mtu,

uint16_t *

max_mtu_out

)

Set the maximum size of ATT Message Transfer Units (MTU). Functionality is the same as sl_bt_gatt_server_set_max_mtu and this setting applies to both GATT client and server. If the given value is too large according to the maximum BGAPI payload size, the system will select the maximum possible value as the maximum ATT_MTU. If the maximum ATT_MTU is larger than 23, the GATT client in the stack will automatically send an MTU exchange request after a Bluetooth connection has been established.

Parameters

[in]

max_mtu

Maximum size of Message Transfer Units (MTU) allowed* Range: 23 to 250

Default: 247 | | [out] | max_mtu_out | The maximum ATT_MTU selected by the system if this command succeeds |

Returns

SL_STATUS_OK if successful. Error code otherwise.

sl_bt_gatt_discover_primary_services()#

sl_status_t sl_bt_gatt_discover_primary_services ( uint8_t connection )

Discover all primary services of a remote GATT database. This command generates a unique gatt_service event for every discovered primary service. Received sl_bt_evt_gatt_procedure_completed event indicates that this GATT procedure has successfully completed or failed with an error.

Parameters

[in]

connection

Connection handle

Returns

SL_STATUS_OK if successful. Error code otherwise.

Events

sl_bt_gatt_discover_primary_services_by_uuid()#

sl_status_t sl_bt_gatt_discover_primary_services_by_uuid

(

uint8_t

connection,

size_t

uuid_len,

const uint8_t *

uuid

)

Discover primary services with the specified UUID in a remote GATT database. This command generates unique gatt_service event for every discovered primary service. Received sl_bt_evt_gatt_procedure_completed event indicates that this GATT procedure was successfully completed or failed with an error.

Parameters

[in]

connection

Connection handle

[in]

uuid_len

Array length

[in]

uuid

Service UUID in little endian format

Returns

SL_STATUS_OK if successful. Error code otherwise.

Events

sl_bt_gatt_find_included_services()#

sl_status_t sl_bt_gatt_find_included_services

(

uint8_t

connection,

uint32_t

service

)

Find the services that are included by a service in a remote GATT database. This command generates a unique gatt_service event for each included service. The received sl_bt_evt_gatt_procedure_completed event indicates that this GATT procedure was successfully completed or failed with an error.

Parameters

[in]

connection

Connection handle

[in]

service

GATT service handle. This value is normally received from the gatt_service event.

Returns

SL_STATUS_OK if successful. Error code otherwise.

Events

sl_bt_gatt_discover_characteristics()#

sl_status_t sl_bt_gatt_discover_characteristics

(

uint8_t

connection,

uint32_t

service

)

Discover all characteristics of a GATT service from a remote GATT database. This command generates a unique gatt_characteristic event for every discovered characteristic. Received sl_bt_evt_gatt_procedure_completed event indicates that this GATT procedure was successfully completed or failed with an error.

Parameters

[in]

connection

Connection handle

[in]

service

GATT service handle. This value is normally received from the gatt_service event.

Returns

SL_STATUS_OK if successful. Error code otherwise.

Events

sl_bt_gatt_discover_characteristics_by_uuid()#

sl_status_t sl_bt_gatt_discover_characteristics_by_uuid

(

uint8_t

connection,

uint32_t

service,

size_t

uuid_len,

const uint8_t *

uuid

)

Discover all characteristics of a GATT service in a remote GATT database having the specified UUID. This command generates a unique gatt_characteristic event for every discovered characteristic having the specified UUID. Received sl_bt_evt_gatt_procedure_completed event indicates that this GATT procedure was successfully completed or failed with an error.

Parameters

[in]

connection

Connection handle

[in]

service

GATT service handle. This value is normally received from the gatt_service event.

[in]

uuid_len

Array length

[in]

uuid

Characteristic UUID in little endian format

Returns

SL_STATUS_OK if successful. Error code otherwise.

Events

sl_bt_gatt_discover_descriptors()#

sl_status_t sl_bt_gatt_discover_descriptors

(

uint8_t

connection,

uint16_t

characteristic

)

Discover all descriptors of a GATT characteristic in a remote GATT database. It generates a unique gatt_descriptor event for every discovered descriptor. Received sl_bt_evt_gatt_procedure_completed event indicates that this GATT procedure has successfully completed or failed with an error.

Parameters

[in]

connection

Connection handle

[in]

characteristic

GATT characteristic handle. This value is normally received from the gatt_characteristic event.

Returns

SL_STATUS_OK if successful. Error code otherwise.

Events

sl_bt_gatt_set_characteristic_notification()#

sl_status_t sl_bt_gatt_set_characteristic_notification

(

uint8_t

connection,

uint16_t

characteristic,

uint8_t

flags

)

Enable or disable the notifications and indications sent from a remote GATT server. This procedure discovers a characteristic client configuration descriptor and writes the related configuration flags to a remote GATT database. A received sl_bt_evt_gatt_procedure_completed event indicates that this GATT procedure was successfully completed or that it failed with an error.

Parameters

[in]

connection

Connection handle

[in]

characteristic

GATT characteristic handle. This value is normally received from the gatt_characteristic event.

[in]

flags

Enum sl_bt_gatt_client_config_flag_t. Characteristic client configuration flags. Values:* sl_bt_gatt_disable (0x0): Disable notifications and indications

  • sl_bt_gatt_notification (0x1): Notification

  • sl_bt_gatt_indication (0x2): Indication |

Returns

SL_STATUS_OK if successful. Error code otherwise.

Events

  • sl_bt_evt_gatt_procedure_completed - Procedure was successfully completed or failed with an error.

  • sl_bt_evt_gatt_characteristic_value - If an indication or notification has been enabled for a characteristic, this event is triggered whenever an indication or notification is sent by the remote GATT server. The triggering conditions of the GATT server are defined by an upper level, for example by a profile. As a result, it is possible that no values are ever received, or that it may take time, depending on how the server is configured.

sl_bt_gatt_send_characteristic_confirmation()#

sl_status_t sl_bt_gatt_send_characteristic_confirmation

(

uint8_t

connection

)

Send a confirmation to a remote GATT server after receiving a characteristic indication. The sl_bt_evt_gatt_characteristic_value event carries the att_opcode containing sl_bt_gatt_handle_value_indication (0x1d), which reveals that an indication has been received and must be confirmed with this command. The confirmation needs to be sent within 30 seconds, otherwise further GATT transactions are not allowed by the remote side.

Parameters

[in]

connection

Connection handle

Returns

SL_STATUS_OK if successful. Error code otherwise.

sl_bt_gatt_read_characteristic_value()#

sl_status_t sl_bt_gatt_read_characteristic_value

(

uint8_t

connection,

uint16_t

characteristic

)

Read the value of a characteristic from a remote GATT database. A single sl_bt_evt_gatt_characteristic_value is generated if the characteristic value fits in one ATT PDU. Otherwise, more than one sl_bt_evt_gatt_characteristic_value event is generated because the firmware will automatically use the Read Long Characteristic Values procedure. A received sl_bt_evt_gatt_procedure_completed event indicates that all data was read successfully or that an error response was received.

Note that the GATT client does not verify if the requested attribute is a characteristic value. Therefore, before calling this command, ensure that the attribute handle is for a characteristic value, for example, by performing characteristic discovery.

Parameters

[in]

connection

Connection handle

[in]

characteristic

GATT characteristic handle. This value is normally received from the gatt_characteristic event.

Returns

SL_STATUS_OK if successful. Error code otherwise.

Events

sl_bt_gatt_read_characteristic_value_from_offset()#

sl_status_t sl_bt_gatt_read_characteristic_value_from_offset

(

uint8_t

connection,

uint16_t

characteristic,

uint16_t

offset,

uint16_t

maxlen

)

Read a partial characteristic value with a specified offset and maximum length from a remote GATT database. It is equivalent to sl_bt_gatt_read_characteristic_value if both the offset and maximum length parameters are 0. A single sl_bt_evt_gatt_characteristic_value event is generated if the value to read fits in one ATT PDU. Otherwise, more than one sl_bt_evt_gatt_characteristic_value events are generated because the firmware will automatically use the Read Long Characteristic Values procedure. A received sl_bt_evt_gatt_procedure_completed event indicates that all data was read successfully or that an error response was received.

Parameters

[in]

connection

Connection handle

[in]

characteristic

GATT characteristic handle. This value is normally received from the gatt_characteristic event.

[in]

offset

Offset of the characteristic value

[in]

maxlen

Maximum bytes to read. If this parameter is 0, all characteristic values starting at a given offset will be read.

Returns

SL_STATUS_OK if successful. Error code otherwise.

Events

sl_bt_gatt_read_multiple_characteristic_values()#

sl_status_t sl_bt_gatt_read_multiple_characteristic_values

(

uint8_t

connection,

size_t

characteristic_list_len,

const uint8_t *

characteristic_list

)

Read values of multiple characteristics from a remote GATT database at once. The GATT server returns values in one ATT PDU as the response. If the total set of values is greater than (ATT_MTU - 1) bytes in length, only the first (ATT_MTU - 1) bytes are included. A single sl_bt_evt_gatt_characteristic_value event is generated, in which the characteristic is set to 0 and data in the value parameter is a concatenation of characteristic values in the order they were requested. The received sl_bt_evt_gatt_procedure_completed event indicates either that this GATT procedure was successfully completed or failed with an error.

Use this command only for characteristics values that have a known fixed size, except the last one that could have variable length.

When the remote GATT server is from Silicon Labs Bluetooth stack, the server returns ATT Invalid PDU (0x04) if this command only reads one characteristic value. The server returns ATT Application Error 0x80 if this command reads the value of a user-type characteristic.

Parameters

[in]

connection

Connection handle

[in]

characteristic_list_len

Array length

[in]

characteristic_list

List of uint16 characteristic handles each in little endian format.

Returns

SL_STATUS_OK if successful. Error code otherwise.

Events

sl_bt_gatt_read_characteristic_value_by_uuid()#

sl_status_t sl_bt_gatt_read_characteristic_value_by_uuid

(

uint8_t

connection,

uint32_t

service,

size_t

uuid_len,

const uint8_t *

uuid

)

Read characteristic values of a service from a remote GATT database by giving the UUID of the characteristic and the handle of the service containing this characteristic. If multiple characteristic values are received in one ATT PDU, one sl_bt_evt_gatt_characteristic_value event is generated for each value. If the first characteristic value does not fit in one ATT PDU, the firmware automatically uses the Read Long Characteristic Values procedure and generate more sl_bt_evt_gatt_characteristic_value events until the value has been completely read. A received sl_bt_evt_gatt_procedure_completed event indicates that all data was read successfully or that an error response was received.

Parameters

[in]

connection

Connection handle

[in]

service

GATT service handle. This value is normally received from the gatt_service event.

[in]

uuid_len

Array length

[in]

uuid

Characteristic UUID in little endian format

Returns

SL_STATUS_OK if successful. Error code otherwise.

Events

sl_bt_gatt_write_characteristic_value()#

sl_status_t sl_bt_gatt_write_characteristic_value

(

uint8_t

connection,

uint16_t

characteristic,

size_t

value_len,

const uint8_t *

value

)

Write the value of a characteristic in a remote GATT database. If the given value does not fit in one ATT PDU, "write long" GATT procedure is used automatically. Received sl_bt_evt_gatt_procedure_completed event indicates that all data was written successfully or that an error response was received.

Parameters

[in]

connection

Connection handle

[in]

characteristic

GATT characteristic handle. This value is normally received from the gatt_characteristic event.

[in]

value_len

Array length

[in]

value

Characteristic value

Returns

SL_STATUS_OK if successful. Error code otherwise.

Events

sl_bt_gatt_write_characteristic_value_without_response()#

sl_status_t sl_bt_gatt_write_characteristic_value_without_response

(

uint8_t

connection,

uint16_t

characteristic,

size_t

value_len,

const uint8_t *

value,

uint16_t *

sent_len

)

Write the value of a characteristic in a remote GATT server. It does not generate an event. All failures on the server are ignored silently. For example, if an error is generated in the remote GATT server and the given value is not written into the database, no error message will be reported to the local GATT client. Note that this command can't be used to write long values. At most ATT_MTU - 3 amount of data can be sent once.

Parameters

[in]

connection

Connection handle

[in]

characteristic

GATT characteristic handle. This value is normally received from the gatt_characteristic event.

[in]

value_len

Array length

[in]

value

Characteristic value

[out]

sent_len

The length of data sent to the remote GATT server

Returns

SL_STATUS_OK if successful. Error code otherwise.

sl_bt_gatt_prepare_characteristic_value_write()#

sl_status_t sl_bt_gatt_prepare_characteristic_value_write

(

uint8_t

connection,

uint16_t

characteristic,

uint16_t

offset,

size_t

value_len,

const uint8_t *

value,

uint16_t *

sent_len

)

Add a characteristic value to the write queue of a remote GATT server. It can be used when long attributes need to be written or a set of values needs to be written atomically. At most ATT_MTU - 5 amount of data can be sent at one time. Writes are executed or canceled with the sl_bt_gatt_execute_characteristic_value_write command. Whether the writes succeed or not is indicated in the response of the sl_bt_gatt_execute_characteristic_value_write command.

In all use cases where the amount of data to transfer fits into the BGAPI payload, use the command sl_bt_gatt_write_characteristic_value to write long values because it transparently performs the prepare_write and execute_write commands.

Parameters

[in]

connection

Connection handle

[in]

characteristic

GATT characteristic handle. This value is normally received from the gatt_characteristic event.

[in]

offset

Offset of the characteristic value

[in]

value_len

Array length

[in]

value

Value to write into the specified characteristic of the remote GATT database

[out]

sent_len

The length of data sent to the remote GATT server

Returns

SL_STATUS_OK if successful. Error code otherwise.

Events

sl_bt_gatt_prepare_characteristic_value_reliable_write()#

sl_status_t sl_bt_gatt_prepare_characteristic_value_reliable_write

(

uint8_t

connection,

uint16_t

characteristic,

uint16_t

offset,

size_t

value_len,

const uint8_t *

value,

uint16_t *

sent_len

)

Add a characteristic value to the write queue of a remote GATT server and verifies whether the value was correctly received by the server. Received sl_bt_evt_gatt_procedure_completed event indicates that this GATT procedure was successfully completed or failed with an error. Specifically, error code 0x0194 (data_corrupted) will be returned if the value received from the GATT server's response fails to pass the reliable write verification. At most, ATT_MTU - 5 amount of data can be sent at one time. Writes are executed or canceled with the sl_bt_gatt_execute_characteristic_value_write command. Whether the writes succeed or not is indicated in the response of the sl_bt_gatt_execute_characteristic_value_write command.

Parameters

[in]

connection

Connection handle

[in]

characteristic

GATT characteristic handle. This value is normally received from the gatt_characteristic event.

[in]

offset

Offset of the characteristic value

[in]

value_len

Array length

[in]

value

Value to write into the specified characteristic of the remote GATT database

[out]

sent_len

The length of data sent to the remote GATT server

Returns

SL_STATUS_OK if successful. Error code otherwise.

Events

sl_bt_gatt_execute_characteristic_value_write()#

sl_status_t sl_bt_gatt_execute_characteristic_value_write

(

uint8_t

connection,

uint8_t

flags

)

Commit or cancel previously queued writes to a long characteristic of a remote GATT server. Writes are sent to the queue with sl_bt_gatt_prepare_characteristic_value_write command. Content, offset, and length of queued values are validated by this procedure. A received sl_bt_evt_gatt_procedure_completed event indicates that all data was written successfully or that an error response was received.

Parameters

[in]

connection

Connection handle

[in]

flags

Enum sl_bt_gatt_execute_write_flag_t. Execute write flag. Values:* sl_bt_gatt_cancel (0x0): Cancel all queued writes

  • sl_bt_gatt_commit (0x1): Commit all queued writes |

Returns

SL_STATUS_OK if successful. Error code otherwise.

Events

sl_bt_gatt_read_descriptor_value()#

sl_status_t sl_bt_gatt_read_descriptor_value

(

uint8_t

connection,

uint16_t

descriptor

)

Read the descriptor value of a characteristic in a remote GATT database. A single sl_bt_evt_gatt_descriptor_value event is generated if the descriptor value fits in one ATT PDU. Otherwise, more than one sl_bt_evt_gatt_descriptor_value events are generated because the firmware automatically uses the Read Long Characteristic Values procedure. A received sl_bt_evt_gatt_procedure_completed event indicates that all data was read successfully or that an error response was received.

Parameters

[in]

connection

Connection handle

[in]

descriptor

GATT characteristic descriptor handle

Returns

SL_STATUS_OK if successful. Error code otherwise.

Events

sl_bt_gatt_write_descriptor_value()#

sl_status_t sl_bt_gatt_write_descriptor_value

(

uint8_t

connection,

uint16_t

descriptor,

size_t

value_len,

const uint8_t *

value

)

Write the value of a characteristic descriptor in a remote GATT database. If the given value does not fit in one ATT PDU, "write long" GATT procedure is used automatically. Received sl_bt_evt_gatt_procedure_completed event indicates either that all data was written successfully or that an error response was received.

Parameters

[in]

connection

Connection handle

[in]

descriptor

GATT characteristic descriptor handle

[in]

value_len

Array length

[in]

value

Descriptor value

Returns

SL_STATUS_OK if successful. Error code otherwise.

Events