Bluetooth: Add permission field to GATT attributes
This field can be used to set the required permissions for an attribute which can be checked by Bluetooth core before calling the callback. Change-Id: Idcab8cdc5744358fab0b3c67b9c0503f1d1d9736 Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
This commit is contained in:
parent
d412b7d799
commit
8c66427b05
|
@ -32,10 +32,20 @@
|
|||
#ifndef __BT_GATT_H
|
||||
#define __BT_GATT_H
|
||||
|
||||
/* GATT attribute permission bitfield values */
|
||||
#define BT_GATT_PERM_READ 0x01
|
||||
#define BT_GATT_PERM_WRITE 0x02
|
||||
#define BT_GATT_PERM_READ_ENCRYPT 0x04
|
||||
#define BT_GATT_PERM_WRITE_ENCRYPT 0x08
|
||||
#define BT_GATT_PERM_READ_AUTHEN 0x10
|
||||
#define BT_GATT_PERM_WRITE_AUTHEN 0x20
|
||||
#define BT_GATT_PERM_AUTHOR 0x40
|
||||
|
||||
/* GATT Attribute structure */
|
||||
struct bt_gatt_attr {
|
||||
uint16_t handle;
|
||||
const struct bt_uuid *uuid;
|
||||
uint8_t perm;
|
||||
int (*read)(const bt_addr_le_t *peer,
|
||||
const struct bt_gatt_attr *attr,
|
||||
void *buf, uint8_t len,
|
||||
|
@ -190,6 +200,7 @@ int bt_gatt_attr_read_service(const bt_addr_le_t *peer,
|
|||
{ \
|
||||
.handle = _handle, \
|
||||
.uuid = _uuid, \
|
||||
.perm = BT_GATT_PERM_READ, \
|
||||
.read = bt_gatt_attr_read_service, \
|
||||
.user_data = _service, \
|
||||
}
|
||||
|
@ -206,6 +217,7 @@ int bt_gatt_attr_read_service(const bt_addr_le_t *peer,
|
|||
.handle = _handle, \
|
||||
.uuid = (&(struct bt_uuid) { .type = BT_UUID_16, \
|
||||
.u16 = BT_UUID_GATT_PRIMARY }), \
|
||||
.perm = BT_GATT_PERM_READ, \
|
||||
.read = bt_gatt_attr_read_service, \
|
||||
.user_data = _service, \
|
||||
}
|
||||
|
@ -222,6 +234,7 @@ int bt_gatt_attr_read_service(const bt_addr_le_t *peer,
|
|||
.handle = _handle, \
|
||||
.uuid = (&(struct bt_uuid) { .type = BT_UUID_16, \
|
||||
.u16 = BT_UUID_GATT_SECONDARY }), \
|
||||
.perm = BT_GATT_PERM_READ, \
|
||||
.read = bt_gatt_attr_read_service, \
|
||||
.user_data = _service, \
|
||||
}
|
||||
|
@ -251,6 +264,7 @@ int bt_gatt_attr_read_included(const bt_addr_le_t *peer,
|
|||
.handle = _handle, \
|
||||
.uuid = (&(struct bt_uuid) { .type = BT_UUID_16, \
|
||||
.u16 = BT_UUID_GATT_INCLUDE }), \
|
||||
.perm = BT_GATT_PERM_READ, \
|
||||
.read = bt_gatt_attr_read_included, \
|
||||
.user_data = _service, \
|
||||
}
|
||||
|
@ -286,6 +300,7 @@ int bt_gatt_attr_read_chrc(const bt_addr_le_t *peer,
|
|||
.handle = _handle, \
|
||||
.uuid = (&(struct bt_uuid) { .type = BT_UUID_16, \
|
||||
.u16 = BT_UUID_GATT_CHRC }), \
|
||||
.perm = BT_GATT_PERM_READ, \
|
||||
.read = bt_gatt_attr_read_chrc, \
|
||||
.user_data = _value, \
|
||||
}
|
||||
|
@ -354,6 +369,7 @@ int bt_gatt_attr_write_ccc(const bt_addr_le_t *peer,
|
|||
.handle = _handle, \
|
||||
.uuid = (&(struct bt_uuid) { .type = BT_UUID_16, \
|
||||
.u16 = BT_UUID_GATT_CCC }), \
|
||||
.perm = BT_GATT_PERM_READ | BT_GATT_PERM_WRITE, \
|
||||
.read = bt_gatt_attr_read_ccc, \
|
||||
.write = bt_gatt_attr_write_ccc, \
|
||||
.user_data = (&(struct _bt_gatt_ccc) { .cfg = _cfg, \
|
||||
|
@ -369,10 +385,11 @@ int bt_gatt_attr_write_ccc(const bt_addr_le_t *peer,
|
|||
* @param _handle descriptor attribute handle
|
||||
* @param _value descriptor attribute value
|
||||
*/
|
||||
#define BT_GATT_DESCRIPTOR(_handle, _uuid, _read, _write, _value) \
|
||||
#define BT_GATT_DESCRIPTOR(_handle, _uuid, _perm, _read, _write, _value) \
|
||||
{ \
|
||||
.handle = _handle, \
|
||||
.uuid = _uuid, \
|
||||
.perm = _perm, \
|
||||
.read = _read, \
|
||||
.write = _write, \
|
||||
.user_data = _value, \
|
||||
|
|
|
@ -268,36 +268,41 @@ static int read_model(const bt_addr_le_t *peer, const struct bt_gatt_attr *attr,
|
|||
static const struct bt_gatt_attr attrs[] = {
|
||||
BT_GATT_PRIMARY_SERVICE(0x0001, &gap_uuid),
|
||||
BT_GATT_CHARACTERISTIC(0x0002, &name_chrc),
|
||||
BT_GATT_DESCRIPTOR(0x0003, &device_name_uuid, read_name, NULL,
|
||||
DEVICE_NAME),
|
||||
BT_GATT_DESCRIPTOR(0x0003, &device_name_uuid, BT_GATT_PERM_READ,
|
||||
read_name, NULL, DEVICE_NAME),
|
||||
BT_GATT_CHARACTERISTIC(0x0004, &appearance_chrc),
|
||||
BT_GATT_DESCRIPTOR(0x0005, &appeareance_uuid, read_appearance, NULL,
|
||||
NULL),
|
||||
BT_GATT_DESCRIPTOR(0x0005, &appeareance_uuid, BT_GATT_PERM_READ,
|
||||
read_appearance, NULL, NULL),
|
||||
/* Heart Rate Service Declaration */
|
||||
BT_GATT_PRIMARY_SERVICE(0x0006, &hrs_uuid),
|
||||
BT_GATT_CHARACTERISTIC(0x0007, &hrmc_chrc),
|
||||
BT_GATT_DESCRIPTOR(0x0008, &hrmc_uuid, NULL, NULL, NULL),
|
||||
BT_GATT_DESCRIPTOR(0x0008, &hrmc_uuid, BT_GATT_PERM_READ, NULL, NULL,
|
||||
NULL),
|
||||
BT_GATT_CCC(0x0009, 0x0008, hrmc_ccc_cfg, hrmc_ccc_cfg_changed),
|
||||
BT_GATT_CHARACTERISTIC(0x000a, &bslc_chrc),
|
||||
BT_GATT_DESCRIPTOR(0x000b, &bslc_uuid, read_blsc, NULL, NULL),
|
||||
BT_GATT_DESCRIPTOR(0x000b, &bslc_uuid, BT_GATT_PERM_READ, read_blsc,
|
||||
NULL, NULL),
|
||||
BT_GATT_CHARACTERISTIC(0x000c, &hrcpc_chrc),
|
||||
/* TODO: Add write permission and callback */
|
||||
BT_GATT_DESCRIPTOR(0x000d, &hrcpc_uuid, NULL, NULL, NULL),
|
||||
BT_GATT_DESCRIPTOR(0x000d, &hrcpc_uuid, BT_GATT_PERM_READ, NULL, NULL,
|
||||
NULL),
|
||||
/* Battery Service Declaration */
|
||||
BT_GATT_PRIMARY_SERVICE(0x000e, &bas_uuid),
|
||||
BT_GATT_CHARACTERISTIC(0x000f, &blvl_chrc),
|
||||
BT_GATT_DESCRIPTOR(0x0010, &blvl_uuid, read_blvl, NULL, NULL),
|
||||
BT_GATT_DESCRIPTOR(0x0010, &blvl_uuid, BT_GATT_PERM_READ, read_blvl,
|
||||
NULL, NULL),
|
||||
BT_GATT_CCC(0x0011, 0x0010, blvl_ccc_cfg, blvl_ccc_cfg_changed),
|
||||
/* Current Time Service Declaration */
|
||||
BT_GATT_PRIMARY_SERVICE(0x0012, &cts_uuid),
|
||||
BT_GATT_CHARACTERISTIC(0x0013, &ct_chrc),
|
||||
BT_GATT_DESCRIPTOR(0x0014, &ct_uuid, read_ct, NULL, NULL),
|
||||
BT_GATT_DESCRIPTOR(0x0014, &ct_uuid, BT_GATT_PERM_READ, read_ct,
|
||||
NULL, NULL),
|
||||
BT_GATT_CCC(0x0015, 0x0014, ct_ccc_cfg, ct_ccc_cfg_changed),
|
||||
/* Device Information Service Declaration */
|
||||
BT_GATT_PRIMARY_SERVICE(0x0016, &dis_uuid),
|
||||
BT_GATT_CHARACTERISTIC(0x0017, &model_chrc),
|
||||
BT_GATT_DESCRIPTOR(0x0018, &model_uuid, read_model, NULL,
|
||||
CONFIG_BSP_DIR),
|
||||
BT_GATT_DESCRIPTOR(0x0018, &model_uuid, BT_GATT_PERM_READ,
|
||||
read_model, NULL, CONFIG_BSP_DIR),
|
||||
};
|
||||
|
||||
static const struct bt_eir ad[] = {
|
||||
|
|
Loading…
Reference in a new issue