bluetooth: services: hrs: added control point write callback
- HRS control point was added to server but no write callback is defined, this causes issues if control point characterstic is written by the client Signed-off-by: Anuj Pathak <anuj@croxel.com>
This commit is contained in:
parent
0705aaeb81
commit
7e1dc5ae3e
2 changed files with 55 additions and 1 deletions
|
@ -25,6 +25,11 @@
|
|||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief Server shall restart the accumulation of energy expended from zero
|
||||
*/
|
||||
#define BT_HRS_CONTROL_POINT_RESET_ENERGY_EXPANDED_REQ 0x01
|
||||
|
||||
/** @brief Heart rate service callback structure */
|
||||
struct bt_hrs_cb {
|
||||
/** @brief Heart rate notifications changed
|
||||
|
@ -34,6 +39,22 @@ struct bt_hrs_cb {
|
|||
*/
|
||||
void (*ntf_changed)(bool enabled);
|
||||
|
||||
/**
|
||||
* @brief Heart rate control point write callback
|
||||
*
|
||||
* @note if Server supports the Energy Expended feature then application
|
||||
* shall implement and support @ref BT_HRS_CONTROL_POINT_RESET_ENERGY_EXPANDED_REQ
|
||||
* request code
|
||||
*
|
||||
* @param request control point request code
|
||||
*
|
||||
* @return 0 on successful handling of control point request
|
||||
* @return -ENOTSUP if not supported. It can be used to pass handling to other
|
||||
* listeners in case of multiple listeners
|
||||
* @return other negative error codes will result in immediate error response
|
||||
*/
|
||||
int (*ctrl_point_write)(uint8_t request);
|
||||
|
||||
/** Internal member to form a list of callbacks */
|
||||
sys_snode_t _node;
|
||||
};
|
||||
|
|
|
@ -45,6 +45,12 @@ LOG_MODULE_REGISTER(hrs);
|
|||
#define CONFIG_BT_HRS_DEFAULT_PERM_RW 0
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief GATT ATTR Error that should be returned in case
|
||||
* HRS Control point request is not supported.
|
||||
*/
|
||||
#define BT_HRS_ATT_ERR_CONTROL_POINT_NOT_SUPPORTED 0x80
|
||||
|
||||
#define HRS_GATT_PERM_DEFAULT ( \
|
||||
CONFIG_BT_HRS_DEFAULT_PERM_RW_AUTHEN ? \
|
||||
(BT_GATT_PERM_READ_AUTHEN | BT_GATT_PERM_WRITE_AUTHEN) : \
|
||||
|
@ -79,6 +85,33 @@ static ssize_t read_blsc(struct bt_conn *conn, const struct bt_gatt_attr *attr,
|
|||
sizeof(hrs_blsc));
|
||||
}
|
||||
|
||||
static ssize_t ctrl_point_write(struct bt_conn *conn, const struct bt_gatt_attr *attr,
|
||||
const void *buf, uint16_t len, uint16_t offset, uint8_t flags)
|
||||
{
|
||||
int err = -ENOTSUP;
|
||||
struct bt_hrs_cb *listener;
|
||||
|
||||
LOG_INF("HRS CTRL Point Written %d", len);
|
||||
|
||||
SYS_SLIST_FOR_EACH_CONTAINER(&hrs_cbs, listener, _node) {
|
||||
if (listener->ctrl_point_write) {
|
||||
err = listener->ctrl_point_write(*((uint8_t *)buf));
|
||||
/* If we get an error other than ENOTSUP then immediately
|
||||
* break the loop and return a generic gatt error, assuming this
|
||||
* listener supports this request code, but failed to serve it
|
||||
*/
|
||||
if ((err != 0) && (err != -ENOTSUP)) {
|
||||
return BT_GATT_ERR(BT_ATT_ERR_UNLIKELY);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (err) {
|
||||
return BT_GATT_ERR(BT_HRS_ATT_ERR_CONTROL_POINT_NOT_SUPPORTED);
|
||||
} else {
|
||||
return len;
|
||||
}
|
||||
}
|
||||
|
||||
/* Heart Rate Service Declaration */
|
||||
BT_GATT_SERVICE_DEFINE(hrs_svc,
|
||||
BT_GATT_PRIMARY_SERVICE(BT_UUID_HRS),
|
||||
|
@ -91,7 +124,7 @@ BT_GATT_SERVICE_DEFINE(hrs_svc,
|
|||
read_blsc, NULL, NULL),
|
||||
BT_GATT_CHARACTERISTIC(BT_UUID_HRS_CONTROL_POINT, BT_GATT_CHRC_WRITE,
|
||||
HRS_GATT_PERM_DEFAULT & GATT_PERM_WRITE_MASK,
|
||||
NULL, NULL, NULL),
|
||||
NULL, ctrl_point_write, NULL),
|
||||
);
|
||||
|
||||
static int hrs_init(void)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue