GATT Client#

GATT Client.

Modules#

sl_bt_evt_gatt_mtu_exchanged

sl_bt_evt_gatt_service

sl_bt_evt_gatt_characteristic

sl_bt_evt_gatt_descriptor

sl_bt_evt_gatt_characteristic_value

sl_bt_evt_gatt_descriptor_value

sl_bt_evt_gatt_procedure_completed

Enumerations#

enum

gatt_att_opcode_t {

 gatt_read_by_type_request = 0x8,

 gatt_read_by_type_response = 0x9,

 gatt_read_request = 0xa,

 gatt_read_response = 0xb,

 gatt_read_blob_request = 0xc,

 gatt_read_blob_response = 0xd,

 gatt_read_multiple_request = 0xe,

 gatt_read_multiple_response = 0xf,

 gatt_write_request = 0x12,

 gatt_write_response = 0x13,

 gatt_write_command = 0x52,

 gatt_prepare_write_request = 0x16,

 gatt_prepare_write_response = 0x17,

 gatt_execute_write_request = 0x18,

 gatt_execute_write_response = 0x19,

 gatt_handle_value_notification = 0x1b,

 gatt_handle_value_indication = 0x1d

}

Attribute Protocol Opcode.

enum

gatt_client_config_flag_t {

 gatt_disable = 0x0,

 gatt_notification = 0x1,

 gatt_indication = 0x2

}

Characteristic Client Configuration Flag.

enum

gatt_execute_write_flag_t {

 gatt_cancel = 0x0,

 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#

gatt_att_opcode_t#

enum gatt_att_opcode_t

Attribute Protocol Opcode.

Enumerator

gatt_read_by_type_request

(0x8) Read by type request

gatt_read_by_type_response

(0x9) Read by type response

gatt_read_request

(0xa) Read request

gatt_read_response

(0xb) Read response

gatt_read_blob_request

(0xc) Read blob request

gatt_read_blob_response

(0xd) Read blob response

gatt_read_multiple_request

(0xe) Read multiple request

gatt_read_multiple_response

(0xf) Read multiple response

gatt_write_request

(0x12) Write request

gatt_write_response

(0x13) Write response

gatt_write_command

(0x52) Write command

gatt_prepare_write_request

(0x16) Prepare write request

gatt_prepare_write_response

(0x17) Prepare write response

gatt_execute_write_request

(0x18) Execute write request

gatt_execute_write_response

(0x19) Execute write response

gatt_handle_value_notification

(0x1b) Notification

gatt_handle_value_indication

(0x1d) Indication

gatt_client_config_flag_t#

enum gatt_client_config_flag_t

Characteristic Client Configuration Flag.

Enumerator

gatt_disable

(0x0) Disable notifications and indications

gatt_notification

(0x1) Notification

gatt_indication

(0x2) Indication

gatt_execute_write_flag_t#

enum gatt_execute_write_flag_t

Execute Write Flag.

Enumerator

gatt_cancel

(0x0) Cancel all queued writes

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 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 	 connection, 
	 uint32 	 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 	 connection, 
	 uint16 	 characteristic, 
	 uint8 	 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 gatt_client_config_flag_t. Characteristic client configuration flags. Values:

  • gatt_disable (0x0): Disable notifications and indications

  • gatt_notification (0x1): Notification

  • 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 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 	 

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, then 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 gatt_execute_write_flag_t. Execute write flag. Values:

  • gatt_cancel (0x0): Cancel all queued writes

  • 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