ATT Server API
#include "src/ble/att_server.h"
att_server_init
void att_server_init(uint8_t const * db, att_read_callback_t read_callback, att_write_callback_t write_callback);
ATT Server
@TLV: 'BTC' x /
/*
setup ATT server
Parameters
- db: attribute database created by compile-gatt.py
- read_callback,: see att_db.h, can be NULL
- write_callback,: see attl.h, can be NULL
att_server_eatt_init
uint8_t att_server_eatt_init(uint8_t num_eatt_bearers, uint8_t * storage_buffer, uint16_t storage_size);
Enable support for Enhanced ATT bearer
Note: Requires ENABLE_GATT_OVER_EATT
Parameters
- num_eatt_bearers
- storage_buffer
- storage_size: must be >= num_eatt_bearers * sizeof(att_server_eatt_bearer_t)
Returns
- uint8_t: status ERROR_CODE_SUCCESS ERROR_CODE_INVALID_HCI_COMMAND_PARAMETERS if num_eatt_bearers is zero or storage_buffer is NULL ERROR_CODE_MEMORY_CAPACITY_EXCEEDED if buffer too small or no entry in l2cap service pool L2CAP_SERVICE_ALREADY_REGISTERED if called twice
att_server_register_packet_handler
void att_server_register_packet_handler(btstack_packet_handler_t handler);
Enable support for Enhanced ATT bearer
Note: Requires ENABLE_GATT_OVER_EATT
register packet handler for ATT server events: - ATT_EVENT_CAN_SEND_NOW - ATT_EVENT_HANDLE_VALUE_INDICATION_COMPLETE - ATT_EVENT_MTU_EXCHANGE_COMPLETE
Parameters
- num_eatt_bearers
- storage_buffer
- storage_size: must be >= num_eatt_bearers * sizeof(att_server_eatt_bearer_t)
- handler
att_server_register_service_handler
void att_server_register_service_handler(att_service_handler_t * handler);
register read/write callbacks for specific handle range
Parameters
- att_service_handler_t
att_server_register_can_send_now_callback
uint8_t att_server_register_can_send_now_callback(btstack_context_callback_registration_t * callback_registration, hci_con_handle_t con_handle);
Request callback when sending is possible
Note: callback might happend during call to this function
Note: pending callback is discarded if the connection disconnects
Parameters
- callback_registration: to point to callback function and context information
- con_handle
Returns
- uint8_t: 0 if ok, error otherwise
att_server_get_mtu
uint16_t att_server_get_mtu(hci_con_handle_t con_handle);
Return ATT MTU
Parameters
- con_handle
Returns
- uint16_t: mtu if ok, 0 otherwise
att_server_request_to_send_notification
uint8_t att_server_request_to_send_notification(btstack_context_callback_registration_t * callback_registration, hci_con_handle_t con_handle);
Request callback when sending notifcation is possible
Note: callback might happend during call to this function
Note: pending callback will be discarded on HCI disconnect
Parameters
- callback_registration: to point to callback function and context information
- con_handle
Returns
- uint8_t: ERROR_CODE_SUCCESS if ok, ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER if handle unknown, and ERROR_CODE_COMMAND_DISALLOWED if callback already registered
att_server_request_to_send_indication
uint8_t att_server_request_to_send_indication(btstack_context_callback_registration_t * callback_registration, hci_con_handle_t con_handle);
Request callback when sending indication is possible
Note: callback might happend during call to this function
Note: pending callback will be discarded on HCI disconnect
Parameters
- callback_registration: to point to callback function and context information
- con_handle
Returns
- uint8_t: ERROR_CODE_SUCCESS if ok, ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER if handle unknown, and ERROR_CODE_COMMAND_DISALLOWED if callback already registered
att_server_notify
uint8_t att_server_notify(hci_con_handle_t con_handle, uint16_t attribute_handle, const uint8_t *value, uint16_t value_len);
notify client about attribute value change
Parameters
- con_handle
- attribute_handle
- value
- value_len
Returns
- uint8_t: 0 if ok, error otherwise
att_server_multiple_notify
uint8_t att_server_multiple_notify(hci_con_handle_t con_handle, uint8_t num_attributes,
const uint16_t * attribute_handles, const uint8_t ** values_data, const uint16_t * values_len);
notify client about multiple attribute value changes
Parameters
- con_handle
- num_attributes
- attribute_handles[]
- values_data[]
- values_len[]
Returns
- uint8_t: 0 if ok, error otherwise
att_server_indicate
uint8_t att_server_indicate(hci_con_handle_t con_handle, uint16_t attribute_handle, const uint8_t *value, uint16_t value_len);
indicate value change to client. client is supposed to reply with an indication_response
Parameters
- con_handle
- attribute_handle
- value
- value_len
Returns
- uint8_t: 0 if ok, error otherwise
#ifdef ENABLE_ATT_DELAYED_RESPONSE
att_server_response_ready
uint8_t att_server_response_ready(hci_con_handle_t con_handle);
response ready - called after returning ATT_READ__RESPONSE_PENDING in an att_read_callback or ATT_ERROR_WRITE_REQUEST_PENDING IN att_write_callback before to trigger callback again and complete the transaction
@nore: The ATT Server will retry handling the current ATT request
Parameters
- con_handle
Returns
- uint8_t: 0 if ok, error otherwise
#endif
att_server_deinit
void att_server_deinit(void);
De-Init ATT Server
// the following functions will be removed soon
att_server_can_send_packet_now
int att_server_can_send_packet_now(hci_con_handle_t con_handle);
tests if a notification or indication can be send right now
Parameters
- con_handle
Returns
- int: 1, if packet can be sent
att_server_request_can_send_now_event
void att_server_request_can_send_now_event(hci_con_handle_t con_handle);
Request emission of ATT_EVENT_CAN_SEND_NOW as soon as possible
Note: ATT_EVENT_CAN_SEND_NOW might be emitted during call to this function so packet handler should be ready to handle it
Parameters
- con_handle
// end of deprecated functions