GATT Server#
GATT Server.
These commands and events are used for accessing to the local GATT server and database.
Modules#
sl_bt_evt_gatt_server_attribute_value
sl_bt_evt_gatt_server_user_read_request
sl_bt_evt_gatt_server_user_write_request
sl_bt_evt_gatt_server_characteristic_status
sl_bt_evt_gatt_server_execute_write_completed
sl_bt_evt_gatt_server_indication_timeout
sl_bt_evt_gatt_server_notification_tx_completed
Enumerations#
These values define whether the server is to sent notifications or indications to a remote GATT server.
These values describe whether the characteristic client configuration was changed or whether a characteristic confirmation was received.
Functions#
Macros#
Enumeration Documentation#
sl_bt_gatt_server_client_configuration_t#
sl_bt_gatt_server_client_configuration_t
These values define whether the server is to sent notifications or indications to a remote GATT server.
Enumerator | |
---|---|
sl_bt_gatt_server_disable | (0x0) Disable notifications and indications. |
sl_bt_gatt_server_notification | (0x1) The characteristic value shall be notified. |
sl_bt_gatt_server_indication | (0x2) The characteristic value shall be indicated. |
sl_bt_gatt_server_notification_and_indication | (0x3) The characteristic value notification and indication are enabled, application decides which one to send. |
9264
of file /mnt/raid/workspaces/ws.nQlGxFofL/overlay/gsdk/protocol/bluetooth/build/native/ble_host/ble_bgapi/inc/sl_bt_api.h
sl_bt_gatt_server_characteristic_status_flag_t#
sl_bt_gatt_server_characteristic_status_flag_t
These values describe whether the characteristic client configuration was changed or whether a characteristic confirmation was received.
Enumerator | |
---|---|
sl_bt_gatt_server_client_config | (0x1) Characteristic client configuration has been changed. |
sl_bt_gatt_server_confirmation | (0x2) Characteristic confirmation has been received. |
9288
of file /mnt/raid/workspaces/ws.nQlGxFofL/overlay/gsdk/protocol/bluetooth/build/native/ble_host/ble_bgapi/inc/sl_bt_api.h
Function Documentation#
sl_bt_gatt_server_set_max_mtu#
sl_status_t sl_bt_gatt_server_set_max_mtu (uint16_t max_mtu, uint16_t * max_mtu_out)
[in] | max_mtu | Maximum size of MTU in the host stack for GATT client and server
|
[out] | max_mtu_out | The maximum size of MTU selected by the host stack |
Set the maximum size of ATT Message Transfer Units (MTU) in the host stack. The functionality is the same as sl_bt_gatt_set_max_mtu and the setting applies to both GATT client and server.
The value will be used as maximum receive MTU size of the GATT server in ATT_EXCHANGE_MTU_RSP. If the GATT client component presents in the application, the value will also be used as the maximum receive MTU size in ATT_EXCHANGE_MTU_REQ. The ATT_MTU on a connection is 23 when the connection is opened. Note that only the GATT Client role can initiate an ATT MTU Exchange request.
If the given value is too large according to the maximum BGAPI payload size, the host stack will select the maximum possible value.
Returns
SL_STATUS_OK if successful. Error code otherwise.
9568
of file /mnt/raid/workspaces/ws.nQlGxFofL/overlay/gsdk/protocol/bluetooth/build/native/ble_host/ble_bgapi/inc/sl_bt_api.h
sl_bt_gatt_server_get_mtu#
sl_status_t sl_bt_gatt_server_get_mtu (uint8_t connection, uint16_t * mtu)
[in] | connection | Connection handle |
[out] | mtu | The maximum ATT_MTU used by the connection |
Get the size of ATT Message Transfer Units (MTU) for a connection.
Returns
SL_STATUS_OK if successful. Error code otherwise.
9581
of file /mnt/raid/workspaces/ws.nQlGxFofL/overlay/gsdk/protocol/bluetooth/build/native/ble_host/ble_bgapi/inc/sl_bt_api.h
sl_bt_gatt_server_find_attribute#
sl_status_t sl_bt_gatt_server_find_attribute (uint16_t start, size_t type_len, const uint8_t * type, uint16_t * attribute)
[in] | start | Search start handle |
[in] | type_len | Length of data in |
[in] | type | The attribute type UUID |
[out] | attribute | Attribute handle |
Find attributes of a certain type from a local GATT database. The type is usually given as a 16-bit or 128-bit UUID in little endian format.
Returns
SL_STATUS_OK if successful. Error code otherwise.
9596
of file /mnt/raid/workspaces/ws.nQlGxFofL/overlay/gsdk/protocol/bluetooth/build/native/ble_host/ble_bgapi/inc/sl_bt_api.h
sl_bt_gatt_server_find_primary_service#
sl_status_t sl_bt_gatt_server_find_primary_service (uint16_t start, size_t uuid_len, const uint8_t * uuid, uint16_t * start_out, uint16_t * end_out)
[in] | start | Search start index |
[in] | uuid_len | Length of data in |
[in] | uuid | Variable-length byte array. The first byte defines the length of data that follows, 0 - 255 bytes. |
[out] | start_out | Group start handle if this command succeeds |
[out] | end_out | Group end handle if this command succeeds |
Find a primary service from local GATT database.
Returns
SL_STATUS_OK if successful. Error code otherwise.
9615
of file /mnt/raid/workspaces/ws.nQlGxFofL/overlay/gsdk/protocol/bluetooth/build/native/ble_host/ble_bgapi/inc/sl_bt_api.h
sl_bt_gatt_server_read_attribute_value#
sl_status_t sl_bt_gatt_server_read_attribute_value (uint16_t attribute, uint16_t offset, size_t max_value_size, size_t * value_len, uint8_t * value)
[in] | attribute | Attribute handle |
[in] | offset | Value offset |
[in] | max_value_size | Size of output buffer passed in |
[out] | value_len | On return, set to the length of output data written to |
[out] | value | The attribute value |
Read the value of an attribute from a local GATT database. Only (maximum BGAPI payload size - 3) amount of data can be read at once. The application can continue reading with increased offset value if it receives (maximum BGAPI payload size - 3) number of bytes.
Returns
SL_STATUS_OK if successful. Error code otherwise.
9638
of file /mnt/raid/workspaces/ws.nQlGxFofL/overlay/gsdk/protocol/bluetooth/build/native/ble_host/ble_bgapi/inc/sl_bt_api.h
sl_bt_gatt_server_read_attribute_type#
sl_status_t sl_bt_gatt_server_read_attribute_type (uint16_t attribute, size_t max_type_size, size_t * type_len, uint8_t * type)
[in] | attribute | Attribute handle |
[in] | max_type_size | Size of output buffer passed in |
[out] | type_len | On return, set to the length of output data written to |
[out] | type | The attribute type UUID |
Read the type of an attribute from a local GATT database. The type is a UUID, usually 16 or 128 bits long in little endian format.
Returns
SL_STATUS_OK if successful. Error code otherwise.
9658
of file /mnt/raid/workspaces/ws.nQlGxFofL/overlay/gsdk/protocol/bluetooth/build/native/ble_host/ble_bgapi/inc/sl_bt_api.h
sl_bt_gatt_server_read_attribute_properties#
sl_status_t sl_bt_gatt_server_read_attribute_properties (uint16_t attribute, uint8_t * category, uint16_t * security, uint16_t * properties, uint8_t * value_type, uint16_t * len, uint16_t * max_writable_len)
[in] | attribute | Attribute handle |
[out] | category | Enum sl_bt_gattdb_attribute_category_t. The high-level attribute category. Values:
|
[out] | security | Security requirement for accessing the attribute. The value is a bitmask of GATT Attribute Security Requirement Flags. |
[out] | properties | The property flags of the attribute. Different flags are used depending on the attribute category specified by
|
[out] | value_type | Enum sl_bt_gattdb_value_type_t. The value type. Values:
|
[out] | len | The current length of the attribute data stored in the local GATT database. This value is set to 0 for attributes that are managed by the user application ( |
[out] | max_writable_len | The maximum writable length of the attribute data stored in the local GATT database. This is independent of the attribute permissions, as even read-only attributes can be writable by the local GATT server. This value is set to 0 for attributes that are not writable or are managed by the user application ( |
Read the properties of an attribute from the local GATT database.
Returns
SL_STATUS_OK if successful. Error code otherwise.
9719
of file /mnt/raid/workspaces/ws.nQlGxFofL/overlay/gsdk/protocol/bluetooth/build/native/ble_host/ble_bgapi/inc/sl_bt_api.h
sl_bt_gatt_server_write_attribute_value#
sl_status_t sl_bt_gatt_server_write_attribute_value (uint16_t attribute, uint16_t offset, size_t value_len, const uint8_t * value)
[in] | attribute | Attribute handle |
[in] | offset | Value offset |
[in] | value_len | Length of data in |
[in] | value | Value |
Write the value of an attribute in the local GATT database. Writing the value of a characteristic of the local GATT database will not trigger notifications or indications to the remote GATT client if the characteristic has a property to indicate or notify and the client has enabled notification or indication. Notifications and indications are sent to the remote GATT client using sl_bt_gatt_server_send_notification or sl_bt_gatt_server_send_indication commands.
Returns
SL_STATUS_OK if successful. Error code otherwise.
9745
of file /mnt/raid/workspaces/ws.nQlGxFofL/overlay/gsdk/protocol/bluetooth/build/native/ble_host/ble_bgapi/inc/sl_bt_api.h
sl_bt_gatt_server_send_user_read_response#
sl_status_t sl_bt_gatt_server_send_user_read_response (uint8_t connection, uint16_t characteristic, uint8_t att_errorcode, size_t value_len, const uint8_t * value, uint16_t * sent_len)
[in] | connection | Connection handle |
[in] | characteristic | GATT characteristic handle received in the sl_bt_evt_gatt_server_user_read_request event. |
[in] | att_errorcode | Attribute protocol error code
|
[in] | value_len | Length of data in |
[in] | value | Characteristic value to send to the GATT client. Ignored if att_errorcode is not 0. |
[out] | sent_len | The length of data sent to the remote GATT client |
Send a response to a sl_bt_evt_gatt_server_user_read_request event. The response needs to be sent within 30 seconds, otherwise no more GATT transactions are allowed by the remote side. If attr_errorcode is set to 0, the characteristic value is sent to the remote GATT client in the standard way. Other attr_errorcode values will cause the local GATT server to send an attribute protocol error response instead of the actual data. Maximum number of bytes this command can send depends on the value of parameter att_opcode in sl_bt_evt_gatt_server_user_read_request event:
ATT_MTU - 1 if the opcode is sl_bt_gatt_read_request or sl_bt_gatt_read_blob_request
ATT_MTU - 4 if the opcode is sl_bt_gatt_read_by_type_request
If the data length in value
exceeds the limit, the first maximum number of bytes will be sent and rest data is ignored. The actual number of bytes that was sent is retruned in the response of this command.
The client will continue reading by sending a new read blob request with an increased offset value if it receives the maximum amount of attribute data the read respond packet can contain.
Returns
SL_STATUS_OK if successful. Error code otherwise.
9787
of file /mnt/raid/workspaces/ws.nQlGxFofL/overlay/gsdk/protocol/bluetooth/build/native/ble_host/ble_bgapi/inc/sl_bt_api.h
sl_bt_gatt_server_send_user_write_response#
sl_status_t sl_bt_gatt_server_send_user_write_response (uint8_t connection, uint16_t characteristic, uint8_t att_errorcode)
[in] | connection | Connection handle |
[in] | characteristic | GATT characteristic handle received in the sl_bt_evt_gatt_server_user_write_request event |
[in] | att_errorcode | Attribute protocol error code
|
Send a response to a sl_bt_evt_gatt_server_user_write_request event when parameter att_opcode
in the event is sl_bt_gatt_write_request or sl_bt_gatt_execute_write_request (see sl_bt_gatt_att_opcode_t). The response needs to be sent within 30 seconds, otherwise no more GATT transactions are allowed by the remote side. When responding to sl_bt_gatt_execute_write_request, the value of parameter characteristic
is ignored. If attr_errorcode is set to 0, the ATT protocol's write response is sent to indicate to the remote GATT client that the write operation was processed successfully. Other values will cause the local GATT server to send an ATT protocol error response.
Returns
SL_STATUS_OK if successful. Error code otherwise.
9818
of file /mnt/raid/workspaces/ws.nQlGxFofL/overlay/gsdk/protocol/bluetooth/build/native/ble_host/ble_bgapi/inc/sl_bt_api.h
sl_bt_gatt_server_send_notification#
sl_status_t sl_bt_gatt_server_send_notification (uint8_t connection, uint16_t characteristic, size_t value_len, const uint8_t * value)
[in] | connection | A handle of the connection over which the notification is sent. |
[in] | characteristic | Characteristic handle |
[in] | value_len | Length of data in |
[in] | value | Value to be notified |
Send a notification to a remote GATT client. At most, ATT_MTU - 3 number of bytes can be sent in a notification. An error SL_STATUS_COMMAND_TOO_LONG is returned if the value length exceeds ATT_MTU - 3.
A notification is sent only if the client has enabled it by setting the corresponding flag to the Client Characteristic Configuration descriptor. The error SL_STATUS_INVALID_PARAMETER is returned if the characteristic does not have the notification property. The error SL_STATUS_INVALID_STATE is returned if the client has not enabled the notification.
Returns
SL_STATUS_OK if successful. Error code otherwise.
9843
of file /mnt/raid/workspaces/ws.nQlGxFofL/overlay/gsdk/protocol/bluetooth/build/native/ble_host/ble_bgapi/inc/sl_bt_api.h
sl_bt_gatt_server_send_indication#
sl_status_t sl_bt_gatt_server_send_indication (uint8_t connection, uint16_t characteristic, size_t value_len, const uint8_t * value)
[in] | connection | A handle of the connection over which the indication is sent. |
[in] | characteristic | Characteristic handle |
[in] | value_len | Length of data in |
[in] | value | Value to be indicated |
Send an indication to a remote GATT client. At most, ATT_MTU - 3 number of bytes can be sent in an indication. An error SL_STATUS_COMMAND_TOO_LONG is returned if the value length exceeds ATT_MTU - 3.
An indication is sent only if the client has enabled it by setting the corresponding flag to the Client Characteristic Configuration descriptor. The error SL_STATUS_INVALID_PARAMETER is returned if the characteristic does not have the indication property. The error SL_STATUS_INVALID_STATE is returned if the client has not enabled the indication.
A new indication to a GATT client can't be sent until an outstanding indication procedure with the same client has completed. The procedure is completed when a confirmation from the client is received. The confirmation is indicated by sl_bt_evt_gatt_server_characteristic_status.
The error SL_STATUS_IN_PROGRESS is returned if an indication procedure with the same client is outstanding. Always wait for confirmation for previous indication before sending a new indication.
Returns
SL_STATUS_OK if successful. Error code otherwise.
Events
sl_bt_evt_gatt_server_characteristic_status - This event is triggered after the confirmation from the client is received.
sl_bt_evt_gatt_server_indication_timeout - This event indicates confirmation from the remote GATT client has not been received within 30 seconds after an indication was sent. Further GATT transactions over this connection are not allowed by the stack.
9886
of file /mnt/raid/workspaces/ws.nQlGxFofL/overlay/gsdk/protocol/bluetooth/build/native/ble_host/ble_bgapi/inc/sl_bt_api.h
sl_bt_gatt_server_notify_all#
sl_status_t sl_bt_gatt_server_notify_all (uint16_t characteristic, size_t value_len, const uint8_t * value)
[in] | characteristic | Characteristic handle |
[in] | value_len | Length of data in |
[in] | value | Value to be notified or indicated |
Send notifications or indications to all connected remote GATT clients. At most, ATT_MTU - 3 number of bytes can be sent in a notification or indication. If the value length exceeds the limit on a connection, the first ATT_MTU - 3 bytes will be sent and rest of data is ignored.
A notification or indication is sent only if the client has enabled it by setting the corresponding flag to the Client Characteristic Configuration descriptor. If the Client Characteristic Configuration descriptor supports both notifications and indications, the stack will always send a notification even when the client has enabled both. This command will not return an error if some clients fail to be notified. Iterate sl_bt_gatt_server_send_notification or sl_bt_gatt_server_send_indication on each connection if the application needs to check that the notification or indication was sent to each client.
A new indication to a GATT client can't be sent until an outstanding indication procedure with the same client has completed, and the operation will continue for the next client. The procedure is completed when a confirmation from the client is received. The confirmation is indicated by sl_bt_evt_gatt_server_characteristic_status.
Returns
SL_STATUS_OK if successful. Error code otherwise.
9921
of file /mnt/raid/workspaces/ws.nQlGxFofL/overlay/gsdk/protocol/bluetooth/build/native/ble_host/ble_bgapi/inc/sl_bt_api.h
sl_bt_gatt_server_read_client_configuration#
sl_status_t sl_bt_gatt_server_read_client_configuration (uint8_t connection, uint16_t characteristic, uint16_t * client_config_flags)
[in] | connection | A handle of the connection to a remote client. |
[in] | characteristic | Characteristic handle |
[out] | client_config_flags | Enum sl_bt_gatt_server_client_configuration_t. Client characteristic configuration of a remote client. |
Read client characteristic configuration of a remote GATT client.
Returns
SL_STATUS_OK if successful. Error code otherwise.
9938
of file /mnt/raid/workspaces/ws.nQlGxFofL/overlay/gsdk/protocol/bluetooth/build/native/ble_host/ble_bgapi/inc/sl_bt_api.h
sl_bt_gatt_server_send_user_prepare_write_response#
sl_status_t sl_bt_gatt_server_send_user_prepare_write_response (uint8_t connection, uint16_t characteristic, uint8_t att_errorcode, uint16_t offset, size_t value_len, const uint8_t * value)
[in] | connection | Connection handle |
[in] | characteristic | GATT characteristic handle. This value is normally received from the gatt_characteristic event. |
[in] | att_errorcode | Attribute protocol error code
|
[in] | offset | Value offset |
[in] | value_len | Length of data in |
[in] | value | Value |
Send a response to a sl_bt_evt_gatt_server_user_write_request event when parameter att_opcode
in the event is sl_bt_gatt_prepare_write_request (see sl_bt_gatt_att_opcode_t). The response needs to be sent within 30 seconds, otherwise no more GATT transactions are allowed by the remote side. If att_errorcode
is set to 0, the ATT protocol's prepare write response is sent to indicate to the remote GATT client that the write operation was processed successfully. Other values will cause the local GATT server to send an ATT protocol error response. The application should set values of parameters offset
and value
to identical values from the sl_bt_evt_gatt_server_user_write_request event. The values will be verified on the client side in case the request is a reliable write (by Bluetooth Core Specification Volume 3, Part G, 4.9.5).
Returns
SL_STATUS_OK if successful. Error code otherwise.
9971
of file /mnt/raid/workspaces/ws.nQlGxFofL/overlay/gsdk/protocol/bluetooth/build/native/ble_host/ble_bgapi/inc/sl_bt_api.h
sl_bt_gatt_server_set_capabilities#
sl_status_t sl_bt_gatt_server_set_capabilities (uint32_t caps, uint32_t reserved)
[in] | caps | Bit flags of capabilities to reset. Value 0 sets the default database capabilities. |
[in] | reserved | Use the value 0 on this reserved field. Do not use none-zero values because they are reserved for future use. |
Reset capabilities that should be enabled by the GATT database. A service is visible to remote GATT clients if at least one of its capabilities is enabled. The same applies to a characteristic and its attributes. Capability identifiers and their corresponding bit flag values are in the auto-generated database header file. See UG118: Blue Gecko Bluetooth Profile Toolkit Developer's Guide for how to declare capabilities in the GATT database.
Changing the capabilities of a database effectively causes a database change (attributes being added or removed) from a remote GATT client point of view. If the database has a Generic Attribute service and Service Changed characteristic, the stack will monitor the local database change status and manage service changed indications for a GATT client that has enabled the indication configuration of the Service Changed characteristic.
Returns
SL_STATUS_OK if successful. Error code otherwise.
10002
of file /mnt/raid/workspaces/ws.nQlGxFofL/overlay/gsdk/protocol/bluetooth/build/native/ble_host/ble_bgapi/inc/sl_bt_api.h
sl_bt_gatt_server_enable_capabilities#
sl_status_t sl_bt_gatt_server_enable_capabilities (uint32_t caps)
[in] | caps | Capabilities to enable |
Enable additional capabilities in the local GATT database. Already enabled capabilities keep unchanged after this command. See sl_bt_gatt_server_set_capabilities for more information.
Returns
SL_STATUS_OK if successful. Error code otherwise.
10016
of file /mnt/raid/workspaces/ws.nQlGxFofL/overlay/gsdk/protocol/bluetooth/build/native/ble_host/ble_bgapi/inc/sl_bt_api.h
sl_bt_gatt_server_disable_capabilities#
sl_status_t sl_bt_gatt_server_disable_capabilities (uint32_t caps)
[in] | caps | Capabilities to disable |
Disable the given capabilities in the local GATT database. See sl_bt_gatt_server_set_capabilities for more information.
Returns
SL_STATUS_OK if successful. Error code otherwise.
10028
of file /mnt/raid/workspaces/ws.nQlGxFofL/overlay/gsdk/protocol/bluetooth/build/native/ble_host/ble_bgapi/inc/sl_bt_api.h
sl_bt_gatt_server_get_enabled_capabilities#
sl_status_t sl_bt_gatt_server_get_enabled_capabilities (uint32_t * caps)
[out] | caps | Enabled capabilities |
Get capabilities currently enabled in the local GATT database.
Returns
SL_STATUS_OK if successful. Error code otherwise.
10039
of file /mnt/raid/workspaces/ws.nQlGxFofL/overlay/gsdk/protocol/bluetooth/build/native/ble_host/ble_bgapi/inc/sl_bt_api.h
sl_bt_gatt_server_read_client_supported_features#
sl_status_t sl_bt_gatt_server_read_client_supported_features (uint8_t connection, uint8_t * client_features)
[in] | connection | A handle of the connection to a remote client. |
[out] | client_features | Bit field describing client supported features of a remote client. See Bluetooth specification Vol 3, Part G, 7.2 for the values. |
Read client supported features of a remote GATT client.
Returns
SL_STATUS_OK if successful. Error code otherwise.
10053
of file /mnt/raid/workspaces/ws.nQlGxFofL/overlay/gsdk/protocol/bluetooth/build/native/ble_host/ble_bgapi/inc/sl_bt_api.h