Soletta™ Framework
|
API to handle Bluetooth technology communications. More...
Data Structures | |
struct | sol_bt_device_info |
Represents a information about a remote device. More... | |
struct | sol_bt_uuid |
Representation of a Bluetooth UUID. More... | |
struct | sol_gatt_attr |
Representation of a GATT Attribute. More... | |
Macros | |
#define | SOL_GATT_ATTR_INVALID { .type = SOL_GATT_ATTR_TYPE_INVALID } |
Terminates the list of attributes. More... | |
#define | SOL_GATT_CHARACTERISTIC_UUID_16(_uuid, _flags,...) |
Helper to the construction of a GATT Characteristic with 16-bit UUID. More... | |
#define | SOL_GATT_DESCRIPTOR_UUID_16(_uuid, _flags,...) |
Helper to the construction of a GATT Descriptor with 16-bit UUID. More... | |
#define | SOL_GATT_SERVICE_UUID_16(service_uuid) |
Helper to the construction of a GATT Service with 16-bit UUID. More... | |
Typedefs | |
typedef struct sol_bt_conn | sol_bt_conn |
Represents an active connection to a Bluetooth device. More... | |
typedef struct sol_bt_device_info | sol_bt_device_info |
Represents a information about a remote device. More... | |
typedef struct sol_bt_scan_pending | sol_bt_scan_pending |
Represents a pending scan session. More... | |
typedef struct sol_bt_session | sol_bt_session |
Represents a Bluetooth usage session. More... | |
typedef struct sol_bt_uuid | sol_bt_uuid |
Representation of a Bluetooth UUID. More... | |
typedef struct sol_gatt_attr | sol_gatt_attr |
Representation of a GATT Attribute. More... | |
typedef struct sol_gatt_pending | sol_gatt_pending |
Represents a pending request. More... | |
Functions | |
const struct sol_network_link_addr * | sol_bt_conn_get_addr (const struct sol_bt_conn *conn) |
Returns the network address of the remote device. More... | |
struct sol_bt_conn * | sol_bt_conn_ref (struct sol_bt_conn *conn) |
Increases the reference count of a connection. More... | |
void | sol_bt_conn_unref (struct sol_bt_conn *conn) |
Decreases the reference count of a connection. More... | |
struct sol_bt_conn * | sol_bt_connect (const struct sol_network_link_addr *addr, bool(*on_connect)(void *user_data, struct sol_bt_conn *conn), void(*on_disconnect)(void *user_data, struct sol_bt_conn *conn), void(*on_error)(void *user_data, int error), const void *user_data) |
Attempts to establish a connection with a remote device. More... | |
int | sol_bt_disable (struct sol_bt_session *session) |
Disables a session, returning the controller to its previous state. More... | |
int | sol_bt_disconnect (struct sol_bt_conn *conn) |
Terminates a connection, or connection attempt. More... | |
struct sol_bt_session * | sol_bt_enable (void(*on_enabled)(void *data, bool powered), const void *user_data) |
Enables the local Bluetooth controller. More... | |
struct sol_bt_scan_pending * | sol_bt_start_scan (enum sol_bt_transport transport, void(*on_found)(void *user_data, const struct sol_bt_device_info *device), const void *user_data) |
Start scanning for devices. More... | |
int | sol_bt_stop_scan (struct sol_bt_scan_pending *handle) |
Stop a scanning session. More... | |
enum sol_bt_transport | sol_bt_transport_from_str (const char *str) |
Converts string to a transport,. More... | |
const char * | sol_bt_transport_to_str (enum sol_bt_transport transport) |
Converts a transport to a string,. More... | |
bool | sol_bt_uuid_eq (const struct sol_bt_uuid *u1, const struct sol_bt_uuid *u2) |
Compare two UUIDs. More... | |
int | sol_bt_uuid_from_str (struct sol_bt_uuid *uuid, const struct sol_str_slice str) |
Convert a string to a UUID. More... | |
int | sol_bt_uuid_to_str (const struct sol_bt_uuid *uuid, struct sol_buffer *buffer) |
Convert a string to a UUID. More... | |
int | sol_gatt_discover (struct sol_bt_conn *conn, enum sol_gatt_attr_type type, const struct sol_gatt_attr *parent, const struct sol_bt_uuid *uuid, bool(*cb)(void *user_data, struct sol_bt_conn *conn, const struct sol_gatt_attr *attr), const void *user_data) |
Discover attributes by type, restricted by UUID and parent attribute. More... | |
int | sol_gatt_indicate (struct sol_bt_conn *conn, const struct sol_gatt_attr *attr) |
Sends an indication to the device represented by conn. More... | |
int | sol_gatt_notify (struct sol_bt_conn *conn, const struct sol_gatt_attr *attr) |
Sends a notificatiion to the device represented by conn. More... | |
const struct sol_gatt_attr * | sol_gatt_pending_get_attr (const struct sol_gatt_pending *op) |
Returns the attribute referenced by a pending operation. More... | |
int | sol_gatt_pending_reply (struct sol_gatt_pending *pending, int error, struct sol_buffer *buf) |
Returns a response to an asynchronous operation. More... | |
int | sol_gatt_read_attr (struct sol_bt_conn *conn, struct sol_gatt_attr *attr, void(*cb)(void *user_data, bool success, const struct sol_gatt_attr *attr, const struct sol_buffer *buf), const void *user_data) |
Reads the value from a attribute. More... | |
int | sol_gatt_register_attributes (struct sol_gatt_attr *attrs) |
Registers attributes into the GATT database. More... | |
int | sol_gatt_subscribe (struct sol_bt_conn *conn, const struct sol_gatt_attr *attr, bool(*cb)(void *user_data, const struct sol_gatt_attr *attr, const struct sol_buffer *buffer), const void *user_data) |
Registers a callback to be called when a notification/indication is received. More... | |
int | sol_gatt_unregister_attributes (struct sol_gatt_attr *attrs) |
Unregisters attributes from the GATT database. More... | |
int | sol_gatt_unsubscribe (bool(*cb)(void *user_data, const struct sol_gatt_attr *attr, const struct sol_buffer *buffer), const void *user_data) |
Unregisters from receiving notifications indications. More... | |
int | sol_gatt_write_attr (struct sol_bt_conn *conn, struct sol_gatt_attr *attr, struct sol_buffer *buf, void(*cb)(void *user_data, bool success, const struct sol_gatt_attr *attr), const void *user_data) |
Writes the value to a attribute. More... | |
API to handle Bluetooth technology communications.
API to handle the GATT protocol.
#define SOL_GATT_ATTR_INVALID { .type = SOL_GATT_ATTR_TYPE_INVALID } |
Terminates the list of attributes.
#define SOL_GATT_CHARACTERISTIC_UUID_16 | ( | _uuid, | |
_flags, | |||
... | |||
) |
Helper to the construction of a GATT Characteristic with 16-bit UUID.
#define SOL_GATT_DESCRIPTOR_UUID_16 | ( | _uuid, | |
_flags, | |||
... | |||
) |
Helper to the construction of a GATT Descriptor with 16-bit UUID.
#define SOL_GATT_SERVICE_UUID_16 | ( | service_uuid | ) |
Helper to the construction of a GATT Service with 16-bit UUID.
Represents an active connection to a Bluetooth device.
The connection is established with sol_bt_connect(), and its lifetime is managed by sol_bt_conn_ref()/sol_bt_conn_unref().
typedef struct sol_bt_device_info sol_bt_device_info |
Represents a information about a remote device.
Represents a Bluetooth usage session.
Because Bluetooth usage may increase the power comsuption, there's a need to keep track of what is using Bluetooth in the system, and keep Bluetooth turned off if it's not used.
typedef struct sol_bt_uuid sol_bt_uuid |
Representation of a Bluetooth UUID.
In Bluetooth, a UUID represents the type of an entity, for example, if a service is encountered in a remote device with the 16-bit UUID '0x111F', that service is a "HandsfreeAudioGateway".
typedef struct sol_gatt_attr sol_gatt_attr |
Representation of a GATT Attribute.
Represents a pending request.
So a response to a GATT operation can be returned asynchronously, operation callbacks,
enum sol_bt_transport |
enum sol_bt_uuid_type |
Set of types of UUIDs.
Bluetooth services (and other entities) types are uniquely identified by UUIDs. In Bluetooth, UUIDs come in different sizes, usually the 16-bit type is reserved to be allocated by the Bluetooth SIG. The 32-bit type is also reserved, but less used. The 128-bit is free to be used by applications.
Enumerator | |
---|---|
SOL_BT_UUID_TYPE_16 | |
SOL_BT_UUID_TYPE_32 | |
SOL_BT_UUID_TYPE_128 |
enum sol_gatt_attr_type |
enum sol_gatt_chr_flags |
Set of flags for Charateristic attributes.
See the Bluetooth Core Specification, Table 3.5 and Table 3.8 for more details.
enum sol_gatt_desc_flags |
Set of flags for Descriptor attributes.
const struct sol_network_link_addr* sol_bt_conn_get_addr | ( | const struct sol_bt_conn * | conn | ) |
Returns the network address of the remote device.
conn | The reference to a connection. |
Referenced by on_connect(), and on_disconnect().
struct sol_bt_conn* sol_bt_conn_ref | ( | struct sol_bt_conn * | conn | ) |
Increases the reference count of a connection.
conn | The reference to a connection. |
void sol_bt_conn_unref | ( | struct sol_bt_conn * | conn | ) |
Decreases the reference count of a connection.
When the last reference is released, the connection and all the resources associated with it are released.
conn | The reference to a connection. |
Referenced by shutdown().
struct sol_bt_conn* sol_bt_connect | ( | const struct sol_network_link_addr * | addr, |
bool(*)(void *user_data, struct sol_bt_conn *conn) | on_connect, | ||
void(*)(void *user_data, struct sol_bt_conn *conn) | on_disconnect, | ||
void(*)(void *user_data, int error) | on_error, | ||
const void * | user_data | ||
) |
Attempts to establish a connection with a remote device.
addr | The network link address of the remote device, |
on_connect | The callback to be called when the connection is established successfully. |
on_disconnect | The callback to be called when the connection is terminated, after established. |
on_error | The callback to be called when the connection cannot be established. |
user_data | User data to be passed to the connection callbacks. |
Referenced by found_device(), and timeout_cb().
int sol_bt_disable | ( | struct sol_bt_session * | session | ) |
Disables a session, returning the controller to its previous state.
In case the session is not already enabled, the enabling attempt will be cancelled after this is called, otherwise the on_enabled()
function provided on the call to sol_bt_enable() will be called with false
powered
argument value.
session | Reference to a session. |
Referenced by shutdown().
int sol_bt_disconnect | ( | struct sol_bt_conn * | conn | ) |
Terminates a connection, or connection attempt.
In case the connection is not already established, the connection attempt will be cancelled after this is called, otherwise the on_disconnect()
function provided on the call to sol_bt_connect() will be called.
conn | The reference to a connection. |
Referenced by shutdown().
struct sol_bt_session* sol_bt_enable | ( | void(*)(void *data, bool powered) | on_enabled, |
const void * | user_data | ||
) |
Enables the local Bluetooth controller.
Before using any other functionality from this module, this function should be called.
In case the Bluetooth controller is already enabled, the enabled() callback will be called before this function returns.
on_enabled | Function to be called when the controller changes state. |
user_data | User data to be provided to the on_enabled callback. |
Referenced by startup().
struct sol_bt_scan_pending* sol_bt_start_scan | ( | enum sol_bt_transport | transport, |
void(*)(void *user_data, const struct sol_bt_device_info *device) | on_found, | ||
const void * | user_data | ||
) |
Start scanning for devices.
If there are already known devices, even if not visible, they will be notified. This function is safe to be called multiple times, the discovery will be stopped when the last user calls sol_bt_stop_scan().
transport | The transport in which to discover devices. |
on_found | The callback to be called for each found device. It may be called multiple times, when the information about the device changes. |
user_data | User data to be passed to the callback. |
Referenced by enabled().
int sol_bt_stop_scan | ( | struct sol_bt_scan_pending * | handle | ) |
Stop a scanning session.
handle | Pointer of an ongoing scanning session. |
Referenced by found_device(), and shutdown().
enum sol_bt_transport sol_bt_transport_from_str | ( | const char * | str | ) |
Converts string to a transport,.
str | A with the transport representation. |
const char* sol_bt_transport_to_str | ( | enum sol_bt_transport | transport | ) |
Converts a transport to a string,.
transport | A transport. |
bool sol_bt_uuid_eq | ( | const struct sol_bt_uuid * | u1, |
const struct sol_bt_uuid * | u2 | ||
) |
Compare two UUIDs.
The UUIDs are converted to their 128-bit representation, if they are of different types, and compared returning if they are equal.
u1 | UUID to be compared. |
u2 | UUID to be compared. |
int sol_bt_uuid_from_str | ( | struct sol_bt_uuid * | uuid, |
const struct sol_str_slice | str | ||
) |
Convert a string to a UUID.
uuid | The uuid in which to store the value. |
str | The string from which to convert. |
int sol_bt_uuid_to_str | ( | const struct sol_bt_uuid * | uuid, |
struct sol_buffer * | buffer | ||
) |
Convert a string to a UUID.
uuid | The uuid to convert. |
buffer | The buffer in which to store the string representation. |
Referenced by print_attr().
int sol_gatt_discover | ( | struct sol_bt_conn * | conn, |
enum sol_gatt_attr_type | type, | ||
const struct sol_gatt_attr * | parent, | ||
const struct sol_bt_uuid * | uuid, | ||
bool(*)(void *user_data, struct sol_bt_conn *conn, const struct sol_gatt_attr *attr) | cb, | ||
const void * | user_data | ||
) |
Discover attributes by type, restricted by UUID and parent attribute.
Discover attributes belonging to a parent attribute, for example, discover all the characteristics under a service or all the descriptors under a characteristic, matching uuid (if provided).
conn | Connection to a remote device |
type | If different from SOL_GATT_ATTR_TYPE_INVALID, only consider attributes of type, |
parent | If different from NULL, only consider attributes belonging to parent attribute. |
uuid | If different from NULL, only consider attributes matching uuid. |
cb | Callback to be called when the conditions above are met. |
user_data | User pointer to be passed to the callback |
Referenced by on_connect().
int sol_gatt_indicate | ( | struct sol_bt_conn * | conn, |
const struct sol_gatt_attr * | attr | ||
) |
Sends an indication to the device represented by conn.
If conn is NULL
, it sends to all devices that have registered themselves via the CCC attribute.
The value to be indicated is the value retrieved by calling the read callback of the attribute.
conn | Connection in which to send notificatiions/indications. |
attr | Attribute to update. |
int sol_gatt_notify | ( | struct sol_bt_conn * | conn, |
const struct sol_gatt_attr * | attr | ||
) |
Sends a notificatiion to the device represented by conn.
If conn is NULL
, it sends to all devices that have registered themselves via the CCC attribute.
The value to be notified is the value retrieved by calling the read callback of the attribute.
conn | Connection in which to send notificatiions/indications. |
attr | Attribute to update. |
Referenced by timeout_cb().
const struct sol_gatt_attr* sol_gatt_pending_get_attr | ( | const struct sol_gatt_pending * | op | ) |
Returns the attribute referenced by a pending operation.
op | The pending operation |
int sol_gatt_pending_reply | ( | struct sol_gatt_pending * | pending, |
int | error, | ||
struct sol_buffer * | buf | ||
) |
Returns a response to an asynchronous operation.
When a operation is performed in a attribute, the response to the operation is only returned when this function is called.
pending | Pending operation to be responded. |
error | Error to be returned, 0 on success. |
buf | Payload (can be NULL) to be returned, on success the payload ownership passes to the function. |
Referenced by hrs_measurement_read().
int sol_gatt_read_attr | ( | struct sol_bt_conn * | conn, |
struct sol_gatt_attr * | attr, | ||
void(*)(void *user_data, bool success, const struct sol_gatt_attr *attr, const struct sol_buffer *buf) | cb, | ||
const void * | user_data | ||
) |
Reads the value from a attribute.
This only really makes sense for Characteristics and Descriptors, the Read Long attribute procedure will be performed if it's supported.
conn | Connection to a remote device |
attr | Attribute to be read |
cb | Callback to be called when the operation is finished |
user_data | User pointer to be passed to the callback |
int sol_gatt_register_attributes | ( | struct sol_gatt_attr * | attrs | ) |
Registers attributes into the GATT database.
attrs | Array of the attributes to be registered |
Referenced by enabled().
int sol_gatt_subscribe | ( | struct sol_bt_conn * | conn, |
const struct sol_gatt_attr * | attr, | ||
bool(*)(void *user_data, const struct sol_gatt_attr *attr, const struct sol_buffer *buffer) | cb, | ||
const void * | user_data | ||
) |
Registers a callback to be called when a notification/indication is received.
It will also try to enable indications/nofications writing to the CCC attribute if that descriptor exists.
conn | Connection to a remote device |
attr | Attribute which to enable Notifications/Indications |
cb | Callback to be called for each update, if you want the notification to be cancelled, return false. |
user_data | User pointer to be passed to the callback |
Referenced by print_attr().
int sol_gatt_unregister_attributes | ( | struct sol_gatt_attr * | attrs | ) |
Unregisters attributes from the GATT database.
attrs | Array of the attributes to be unregistered |
Referenced by shutdown().
int sol_gatt_unsubscribe | ( | bool(*)(void *user_data, const struct sol_gatt_attr *attr, const struct sol_buffer *buffer) | cb, |
const void * | user_data | ||
) |
Unregisters from receiving notifications indications.
cb | Callback previously set |
user_data | User pointer |
int sol_gatt_write_attr | ( | struct sol_bt_conn * | conn, |
struct sol_gatt_attr * | attr, | ||
struct sol_buffer * | buf, | ||
void(*)(void *user_data, bool success, const struct sol_gatt_attr *attr) | cb, | ||
const void * | user_data | ||
) |
Writes the value to a attribute.
This only really makes sense for Characteristics and Descriptors, the Write Long attribute procedure will be performed if it's supported.
conn | Connection to a remote device |
attr | Attribute to be written |
buf | Buffer to be written, on success the ownership passes to the function. |
cb | Callback to be called when the operation is finished |
user_data | User pointer to be passed to the callback |