dotstack API Reference  1.10.37
Modules | Data Structures | Typedefs | Functions
ATT Server

This module describes functions and data structures used to implement an ATT server (peripheral). More...

Modules

 Configuration
 This module describes parameters used to configure ATT server layer.
 

Data Structures

struct  bt_att_evt_session_connected_t
 Parameter to ATT_SERVER_EVT_SESSION_CONNECTED event. More...
 
struct  bt_att_evt_session_disconnected_t
 Parameter to ATT_SERVER_EVT_SESSION_DISCONNECTED event. More...
 
struct  bt_att_evt_attr_value_changed_t
 Parameter to ATT_SERVER_EVT_ATTR_VALUE_CHANGED_BY_SERVER and ATT_SERVER_EVT_ATTR_VALUE_CHANGED_BY_CLIENT events. More...
 
struct  bt_att_evt_attr_value_read_t
 Parameter to ATT_SERVER_EVT_ATTR_VALUE_READ event. More...
 
struct  bt_att_evt_attr_notification_sent_t
 Parameter to ATT_SERVER_EVT_ATTR_VALUE_NOTIFIED event. More...
 
struct  bt_att_evt_attr_indication_sent_t
 Parameter to ATT_SERVER_EVT_ATTR_VALUE_INDICATED event. More...
 
struct  bt_att_evt_tran_timeout_t
 Parameter to ATT_SERVER_EVT_TRAN_TIMEOUT event. More...
 
struct  bt_att_evt_authorization_requested_t
 Parameter to ATT_SERVER_EVT_AUTHORIZATION_REQUESTED event. More...
 
struct  bt_att_mgr_t
 ATT manager. More...
 

Typedefs

typedef void(* bt_att_mgr_callback_fp) (bt_int evt, void *evt_param, void *param)
 ATT application callback. More...
 

Functions

bt_bool bt_att_init (void)
 Initialize the ATT layer. More...
 
bt_att_mgr_tbt_att_get_mgr (void)
 Return a pointer to an instance of the ATT manager. More...
 
bt_bool bt_att_register_listener (bt_att_listener_t *listener)
 Register an ATT event listener. More...
 
void bt_att_unregister_listener (bt_att_listener_t *listener)
 Unregister an ATT event listener. More...
 
bt_bool bt_att_update_conn_parameters (bt_att_session_t *session, bt_uint min_interval, bt_uint max_interval, bt_uint slave_latency, bt_uint supervision_timeout)
 Request connection parameters update. More...
 
bt_bdaddr_t * bt_att_get_remote_address (const bt_att_session_t *session)
 Get the address of the remote device this device is connected to. More...
 
bt_bool bt_att_server_start (bt_byte *att_var_db, bt_uint att_var_db_len, const bt_byte *att_const_db, bt_uint att_const_db_len, bt_bool listen_on_dynamic_channel)
 Start ATT server. More...
 
void bt_att_server_stop (void)
 Stop ATT server. More...
 
void bt_att_server_register_callback (bt_att_server_callback_fp callback, void *param)
 Register a ATT application callback. More...
 
bt_byte bt_att_server_write_attribute_value (bt_uint handle, const bt_byte *value, bt_uint value_len, bt_uint offset)
 Write attribute's value. More...
 
bt_bool bt_att_server_disconnect (bt_att_session_t *session)
 Disconnect from a remote device. More...
 
void bt_att_server_indicate_to_all (bt_att_attribute_t *attr)
 Indicate attribute's value to all connected clients. More...
 
void bt_att_server_indicate (bt_att_session_t *session, bt_att_attribute_t *attr)
 Indicate attribute's value. More...
 
void bt_att_server_notify_all (bt_att_attribute_t *attr)
 Notify attribute's value to all connected clients. More...
 
void bt_att_server_notify (bt_att_session_t *session, bt_att_attribute_t *attr)
 Notify attribute's value. More...
 
void bt_att_server_authorize_access (bt_att_session_t *session, bt_att_attribute_t *attr, bt_byte opcode, bt_bool authorize)
 Authorize access to an attribute. More...
 

Events

#define ATT_SERVER_EVT_SESSION_CONNECTED   ATT_MGR_EVT_SESSION_CONNECTED
 A client connected to the server.
 
#define ATT_SERVER_EVT_SESSION_DISCONNECTED   ATT_MGR_EVT_SESSION_DISCONNECTED
 A client disconnected from the server.
 
#define ATT_SERVER_EVT_ATTR_VALUE_CHANGED_BY_SERVER   ATT_MGR_EVT_ATTR_VALUE_CHANGED_BY_SERVER
 Attribute's value has been changed locally on the server.
 
#define ATT_SERVER_EVT_ATTR_VALUE_CHANGED_BY_CLIENT   ATT_MGR_EVT_ATTR_VALUE_CHANGED_BY_CLIENT
 A client has changed the attribute's value.
 
#define ATT_SERVER_EVT_ATTR_VALUE_NOTIFIED   ATT_MGR_EVT_ATTR_VALUE_NOTIFIED
 A value notification has bee sent to the client.
 
#define ATT_SERVER_EVT_ATTR_VALUE_INDICATED   ATT_MGR_EVT_ATTR_VALUE_INDICATED
 A value indication has been sent to the client.
 
#define ATT_SERVER_EVT_TRAN_TIMEOUT   ATT_MGR_EVT_TRAN_TIMEOUT
 Operation timed out.
 
#define ATT_SERVER_EVT_AUTHORIZATION_REQUESTED   ATT_MGR_EVT_AUTHORIZATION_REQUESTED
 Authorization is required in order to access the attribute's value.
 
#define ATT_SERVER_EVT_ATTR_VALUE_READ_BY_CLIENT   ATT_MGR_EVT_ATTR_VALUE_READ_BY_CLIENT
 A client has read the attribute's value.
 
#define ATT_SERVER_EVT_STOPPED   50
 Server stoped.
 

Detailed Description

This module describes functions and data structures used to implement an ATT server (peripheral).

Typedef Documentation

typedef void(* bt_att_mgr_callback_fp) (bt_int evt, void *evt_param, void *param)

ATT application callback.

In order to be notified of various events a consumer of the ATT layer has to register a callback function. The stack will call this function whenever a new event has been generated passing the code of the event as the first parameter.

Parameters
evtATT event
evt_paramEvent parameter. This can be one of the following values:
  • ATT_SERVER_EVT_SESSION_CONNECTED A client connected to the server
  • ATT_SERVER_EVT_SESSION_DISCONNECTED A client disconnected from the server
  • ATT_SERVER_EVT_ATTR_VALUE_CHANGED_BY_SERVER Attribute's value has been changed locally on the server
  • ATT_SERVER_EVT_ATTR_VALUE_CHANGED_BY_CLIENT A client has changed the attribute's value
  • ATT_SERVER_EVT_ATTR_VALUE_NOTIFIED A value notification has bee sent to the client
  • ATT_SERVER_EVT_ATTR_VALUE_INDICATED A value indication has been sent to the client
  • ATT_SERVER_EVT_TRAN_TIMEOUT Operation timed out
  • ATT_SERVER_EVT_AUTHORIZATION_REQUESTED Authorization is required in order to access the attribute's value
  • ATT_SERVER_EVT_STOPPED Server stooped
callback_paramA pointer to an arbitrary data set by a call to bt_att_server_register_callback.

Function Documentation

bt_att_mgr_t* bt_att_get_mgr ( void  )

Return a pointer to an instance of the ATT manager.

This function returns a pointer to an instance of the ATT manager. There is only one instance of the manager allocated by the stack.

bt_bdaddr_t* bt_att_get_remote_address ( const bt_att_session_t *  session)

Get the address of the remote device this device is connected to.

Parameters
sessionATT session.
Returns
  • A pointer to bt_bdaddr structure that contains the address of the remote device.
bt_bool bt_att_init ( void  )

Initialize the ATT layer.

This function initializes the ATT layer of the stack. It must be called prior to any other ATT function can be called.

bt_bool bt_att_register_listener ( bt_att_listener_t listener)

Register an ATT event listener.

In order to be notified of various events a consumer of the ATT layer may register an event listener. The listener is a structure that contains a pointer to a callback function and a callback parameter - a pointer to arbitrary data to be passed to the callback function. The stack will call the callback whenever a new event has been generated passing the code of the event as the first parameter. The event can be one of the following values:

  • ATT_SERVER_EVT_SESSION_CONNECTED A client connected to the server
  • ATT_SERVER_EVT_SESSION_DISCONNECTED A client disconnected from the server
  • ATT_SERVER_EVT_ATTR_VALUE_CHANGED_BY_SERVER Attribute's value has been changed locally on the server
  • ATT_SERVER_EVT_ATTR_VALUE_CHANGED_BY_CLIENT A client has changed the attribute's value
  • ATT_SERVER_EVT_ATTR_VALUE_NOTIFIED A value notification has bee sent to the client
  • ATT_SERVER_EVT_ATTR_VALUE_INDICATED A value indication has been sent to the client
  • ATT_SERVER_EVT_TRAN_TIMEOUT Transaction timed out
  • ATT_SERVER_EVT_AUTHORIZATION_REQUESTED Authorization is required in order to access the attribute's value
  • ATT_SERVER_EVT_STOPPED Server stooped
Parameters
listenerA pointer to a structure containing the listener parameters. The pointer has to be persistent, i.e., it cannot be allocate on the stack.
void bt_att_server_authorize_access ( bt_att_session_t *  session,
bt_att_attribute_t attr,
bt_byte  opcode,
bt_bool  authorize 
)

Authorize access to an attribute.

If an attribute requires authorization before its value can be read or written, ATT generates a ATT_SERVER_EVT_AUTHORIZATION_REQUESTED event. In response to this event the application should obtain authorization (how this is done is implementation specific) and call bt_att_server_authorize_access.

Parameters
sessionATT session.
attrAttribute.
opcodeAttribute Opcode. The opcode that requires authorization is passed in the ATT_SERVER_EVT_AUTHORIZATION_REQUESTED event. The application should use the passed opcode when calling bt_att_server_authorize_access. The opcode can be one the following values:
  • ATT_OPCODE_READ_REQUEST
  • ATT_OPCODE_READ_BLOB_REQUEST
  • ATT_OPCODE_READ_BY_TYPE_REQUEST
  • ATT_OPCODE_READ_BY_GROUP_TYPE_REQUEST
  • ATT_OPCODE_READ_MULTIPLE_REQUEST
  • ATT_OPCODE_WRITE_REQUEST
  • ATT_OPCODE_PREPARE_WRITE_REQUEST
authorizeSpecifies whether access to the attribute has been authorized or not.
bt_bool bt_att_server_disconnect ( bt_att_session_t *  session)

Disconnect from a remote device.

This function closes a connection to a remote device.

Parameters
sessionATT session.
Returns
  • TRUE if disconnection has been started.
  • FALSE otherwise. No events will be generated.
void bt_att_server_indicate ( bt_att_session_t *  session,
bt_att_attribute_t attr 
)

Indicate attribute's value.

This function sends the attribute's value specified with the attr parameter to a client specified with the session parameter.

Parameters
sessionATT session.
attrAttribute.
void bt_att_server_indicate_to_all ( bt_att_attribute_t attr)

Indicate attribute's value to all connected clients.

This function sends the attribute's value specified with the attr parameter to all connected clients.

Parameters
attrAttribute.
void bt_att_server_notify ( bt_att_session_t *  session,
bt_att_attribute_t attr 
)

Notify attribute's value.

This function sends the attribute's value specified with the attr parameter to a client specified with the session parameter.

Parameters
sessionATT session.
attrAttribute.
void bt_att_server_notify_all ( bt_att_attribute_t attr)

Notify attribute's value to all connected clients.

This function sends the attribute's value specified with the attr parameter to all connected clients.

Parameters
sessionATT session.
attrAttribute.
void bt_att_server_register_callback ( bt_att_server_callback_fp  callback,
void *  param 
)

Register a ATT application callback.

In order to be notified of various events a consumer of the ATT layer has to register a callback function. The stack will call this function whenever a new event has been generated passing the code of the event as the first parameter. The event can be one of the following values:

  • ATT_SERVER_EVT_SESSION_CONNECTED A client connected to the server
  • ATT_SERVER_EVT_SESSION_DISCONNECTED A client disconnected from the server
  • ATT_SERVER_EVT_ATTR_VALUE_CHANGED_BY_SERVER Attribute's value has been changed locally on the server
  • ATT_SERVER_EVT_ATTR_VALUE_CHANGED_BY_CLIENT A client has changed the attribute's value
  • ATT_SERVER_EVT_ATTR_VALUE_NOTIFIED A value notification has bee sent to the client
  • ATT_SERVER_EVT_ATTR_VALUE_INDICATED A value indication has been sent to the client
  • ATT_SERVER_EVT_TRAN_TIMEOUT Transaction timed out
  • ATT_SERVER_EVT_AUTHORIZATION_REQUESTED Authorization is required in order to access the attribute's value
  • ATT_SERVER_EVT_STOPPED Server stooped
Parameters
callbackThe callback function that will be called when ATT generates an event.
callback_paramA pointer to arbitrary data to be passed to the callback callback.
bt_bool bt_att_server_start ( bt_byte *  att_var_db,
bt_uint  att_var_db_len,
const bt_byte *  att_const_db,
bt_uint  att_const_db_len,
bt_bool  listen_on_dynamic_channel 
)

Start ATT server.

This function starts the ATT server.

Parameters
att_var_dbA pointer to ATT database that holds writable attributes.
att_var_db_lenThe length of the writable ATT database.
att_const_dbA pinter to ATT database that holds read-only attributes.
att_const_db_lenThe length of the read-only ATT database.
listen_on_dynamic_channelSpecifies whether ATT server should accept connections on BR/EDR links.
Returns
  • TRUE if the function succeeds.
  • FALSE otherwise.
void bt_att_server_stop ( void  )

Stop ATT server.

This function stops the ATT server.

Returns
  • TRUE if the function succeeds.
  • FALSE otherwise.
bt_byte bt_att_server_write_attribute_value ( bt_uint  handle,
const bt_byte *  value,
bt_uint  value_len,
bt_uint  offset 
)

Write attribute's value.

This function writes attribute's value.

Parameters
handleAttribute handle.
valueAttribute value.
value_lenAttribute value length.
offsetOffset from which to write the value.
Returns
Error code. This can be one of the following values:
  • ATT_ERROR_SUCCESS
  • ATT_ERROR_INVALID_HANDLE
  • ATT_ERROR_READ_NOT_PERMITTED
  • ATT_ERROR_WRITE_NOT_PERMITTED
  • ATT_ERROR_INVALID_PDU
  • ATT_ERROR_INSUFFICIENT_AUTHENTICATION
  • ATT_ERROR_REQUEST_NOT_SUPPORTED
  • ATT_ERROR_INVALID_OFFSET
  • ATT_ERROR_INSUFFICIENT_AUTHORIZATION
  • ATT_ERROR_PREPARE_QUEUE_FULL
  • ATT_ERROR_ATTRIBUTE_NOT_FOUND
  • ATT_ERROR_ATTRIBUTE_NOT_LONG
  • ATT_ERROR_INSUFFICIENT_ENCRYPTION_KEY_SIZE
  • ATT_ERROR_INVALID_ATTRIBUTE_VALUE_LENGTH
  • ATT_ERROR_UNLIKELY_ERROR
  • ATT_ERROR_INSUFFICIENT_ENCRYPTION
  • ATT_ERROR_UNSUPPORTED_GROUP_TYPE
  • ATT_ERROR_INSUFFICIENT_RESOURCES
void bt_att_unregister_listener ( bt_att_listener_t listener)

Unregister an ATT event listener.

Remove a listener previously registered with bt_att_register_listener.

Parameters
listenerA pointer to a structure containing the listener parameters. It has to be the the same pinter passed to bt_att_register_listener().
bt_bool bt_att_update_conn_parameters ( bt_att_session_t *  session,
bt_uint  min_interval,
bt_uint  max_interval,
bt_uint  slave_latency,
bt_uint  supervision_timeout 
)

Request connection parameters update.

This function sends a request to the client (central) to update connection parameters.

Parameters
sessionATT session.
min_intervalMinimum connection interval in milliseconds.
max_intervalMaximum connection interval in milliseconds.
slave_latencySlave latency expressed as number of connection events.
supervision_timeoutLink supervision timeout in milliseconds.
Returns
  • TRUE if request has been sent to the central.
  • FALSE otherwise.