Bluetooth: host: cfg_write callback to return error code
Current implementation of application's cfg_write callback only has the possibility of returning boolean status, which in case of failure only allows for one error code; BT_ATT_ERR_WRITE_NOT_PERMITTED. This change makes the application able to add own security check on characteristic subscription in the cfg_write callback and report a more relevant error code (e.g. BT_ATT_ERR_AUTHORIZATION). Signed-off-by: Kim Sekkelund <ksek@oticon.com>
This commit is contained in:
parent
c336539249
commit
9ea6e72bae
3 changed files with 58 additions and 22 deletions
|
@ -571,15 +571,43 @@ struct bt_gatt_ccc_cfg {
|
|||
|
||||
/* Internal representation of CCC value */
|
||||
struct _bt_gatt_ccc {
|
||||
struct bt_gatt_ccc_cfg cfg[BT_GATT_CCC_MAX];
|
||||
u16_t value;
|
||||
void (*cfg_changed)(const struct bt_gatt_attr *attr,
|
||||
u16_t value);
|
||||
bool (*cfg_write)(struct bt_conn *conn,
|
||||
const struct bt_gatt_attr *attr,
|
||||
u16_t value);
|
||||
bool (*cfg_match)(struct bt_conn *conn,
|
||||
const struct bt_gatt_attr *attr);
|
||||
/** Configuration for each connection */
|
||||
struct bt_gatt_ccc_cfg cfg[BT_GATT_CCC_MAX];
|
||||
|
||||
/** Highest value of all connected peer's subscriptions */
|
||||
u16_t value;
|
||||
|
||||
/** CCC attribute changed callback
|
||||
*
|
||||
* @param attr The attribute that's changed value
|
||||
* @param value New value
|
||||
*/
|
||||
void (*cfg_changed)(const struct bt_gatt_attr *attr, u16_t value);
|
||||
|
||||
/** CCC attribute write validation callback
|
||||
*
|
||||
* @param conn The connection that is requesting to write
|
||||
* @param attr The attribute that's being written
|
||||
* @param value CCC value to write
|
||||
*
|
||||
* @return Number of bytes to write, or in case of an error
|
||||
* BT_GATT_ERR() with a specific error code.
|
||||
*/
|
||||
ssize_t (*cfg_write)(struct bt_conn *conn,
|
||||
const struct bt_gatt_attr *attr, u16_t value);
|
||||
|
||||
/** CCC attribute match handler
|
||||
* Indicate if it is OK to send a notification or indication
|
||||
* to the subscriber.
|
||||
*
|
||||
* @param conn The connection that is being checked
|
||||
* @param attr The attribute that's being checked
|
||||
*
|
||||
* @return true if application has approved notification/indication,
|
||||
* false if application does not approve.
|
||||
*/
|
||||
bool (*cfg_match)(struct bt_conn *conn,
|
||||
const struct bt_gatt_attr *attr);
|
||||
};
|
||||
|
||||
/** @brief Read Client Characteristic Configuration Attribute helper.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue