From 1b038f294114797a2aecdfdae76198520efbb7f6 Mon Sep 17 00:00:00 2001 From: Luiz Augusto von Dentz Date: Fri, 11 May 2018 21:53:02 +0300 Subject: [PATCH] Bluetooth: GATT: Make BT_GATT_CHARACTERISTIC declare its value This ensures the every characteristic has a value attribute declared with the same UUID since the old macro did not declare the value the application would normally have to declare one itself using a different UUID which is not allowed. Signed-off-by: Luiz Augusto von Dentz --- include/bluetooth/gatt.h | 14 ++- samples/bluetooth/eddystone/src/main.c | 117 +++++++----------- samples/bluetooth/gatt/bas.c | 5 +- samples/bluetooth/gatt/cts.c | 7 +- samples/bluetooth/gatt/dis.c | 10 +- samples/bluetooth/gatt/hog.c | 22 ++-- samples/bluetooth/gatt/hrs.c | 16 +-- samples/bluetooth/peripheral/src/main.c | 34 +++-- samples/bluetooth/peripheral_csc/src/main.c | 21 ++-- samples/bluetooth/peripheral_esp/src/main.c | 18 +-- .../environmental_sensing/ap/src/main.c | 17 ++- samples/boards/microbit/pong/src/ble.c | 5 +- subsys/bluetooth/host/gatt.c | 25 ++-- subsys/bluetooth/host/mesh/proxy.c | 23 ++-- subsys/bluetooth/shell/gatt.c | 43 +++---- tests/bluetooth/tester/src/gatt.c | 7 +- 16 files changed, 175 insertions(+), 209 deletions(-) diff --git a/include/bluetooth/gatt.h b/include/bluetooth/gatt.h index 1145ca175d5..4e7bffca6d7 100644 --- a/include/bluetooth/gatt.h +++ b/include/bluetooth/gatt.h @@ -457,18 +457,24 @@ ssize_t bt_gatt_attr_read_chrc(struct bt_conn *conn, u16_t len, u16_t offset); /** @def BT_GATT_CHARACTERISTIC - * @brief Characteristic Declaration Macro. + * @brief Characteristic and Value Declaration Macro. * - * Helper macro to declare a characteristic attribute. + * Helper macro to declare a characteristic attribute along with its + * attribute value. * * @param _uuid Characteristic attribute uuid. * @param _props Characteristic attribute properties. + * @param _perm Characteristic Attribute access permissions. + * @param _read Characteristic Attribute read callback. + * @param _write Characteristic Attribute write callback. + * @param _value Characteristic Attribute value. */ -#define BT_GATT_CHARACTERISTIC(_uuid, _props) \ +#define BT_GATT_CHARACTERISTIC(_uuid, _props, _perm, _read, _write, _value) \ BT_GATT_ATTRIBUTE(BT_UUID_GATT_CHRC, BT_GATT_PERM_READ, \ bt_gatt_attr_read_chrc, NULL, \ (&(struct bt_gatt_chrc) { .uuid = _uuid, \ - .properties = _props, })) + .properties = _props, })), \ + BT_GATT_ATTRIBUTE(_uuid, _perm, _read, _write, _value) #define BT_GATT_CCC_MAX (CONFIG_BT_MAX_PAIRED + CONFIG_BT_MAX_CONN) diff --git a/samples/bluetooth/eddystone/src/main.c b/samples/bluetooth/eddystone/src/main.c index 52195088340..354a8cd11c7 100644 --- a/samples/bluetooth/eddystone/src/main.c +++ b/samples/bluetooth/eddystone/src/main.c @@ -566,85 +566,62 @@ static ssize_t write_connectable(struct bt_conn *conn, /* Eddystone Configuration Service Declaration */ static struct bt_gatt_attr eds_attrs[] = { BT_GATT_PRIMARY_SERVICE(&eds_uuid), - /* Capabilities */ - BT_GATT_CHARACTERISTIC(&eds_caps_uuid.uuid, BT_GATT_CHRC_READ), - /* Readable only when unlocked. Never writable. */ - BT_GATT_DESCRIPTOR(&eds_caps_uuid.uuid, BT_GATT_PERM_READ, - read_caps, NULL, &eds_caps), - /* Active slot */ + /* Capabilities: Readable only when unlocked. Never writable. */ + BT_GATT_CHARACTERISTIC(&eds_caps_uuid.uuid, BT_GATT_CHRC_READ, + BT_GATT_PERM_READ, read_caps, NULL, &eds_caps), + /* Active slot: Must be unlocked for both read and write. */ BT_GATT_CHARACTERISTIC(&eds_slot_uuid.uuid, - BT_GATT_CHRC_READ | BT_GATT_CHRC_WRITE), - /* Must be unlocked for both read and write. */ - BT_GATT_DESCRIPTOR(&eds_slot_uuid.uuid, - BT_GATT_PERM_READ | BT_GATT_PERM_WRITE, - read_slot, write_slot, NULL), - /* Advertising Interval */ - BT_GATT_CHARACTERISTIC(&eds_intv_uuid.uuid, BT_GATT_CHRC_READ), - /* Must be unlocked for both read and write. */ - BT_GATT_DESCRIPTOR(&eds_intv_uuid.uuid, BT_GATT_PERM_READ, - read_interval, NULL, NULL), - /* Radio TX Power */ + BT_GATT_CHRC_READ | BT_GATT_CHRC_WRITE, + BT_GATT_PERM_READ | BT_GATT_PERM_WRITE, + read_slot, write_slot, NULL), + /* Advertising Interval: Must be unlocked for both read and write. */ + BT_GATT_CHARACTERISTIC(&eds_intv_uuid.uuid, BT_GATT_CHRC_READ, + BT_GATT_PERM_READ, read_interval, NULL, NULL), + /* Radio TX Power: Must be unlocked for both read and write. */ BT_GATT_CHARACTERISTIC(&eds_tx_uuid.uuid, - BT_GATT_CHRC_READ | BT_GATT_CHRC_WRITE), - /* Must be unlocked for both read and write. */ - BT_GATT_DESCRIPTOR(&eds_tx_uuid.uuid, - BT_GATT_PERM_READ | BT_GATT_PERM_WRITE, - read_tx_power, write_tx_power, NULL), - /* Advertised TX Power */ + BT_GATT_CHRC_READ | BT_GATT_CHRC_WRITE, + BT_GATT_PERM_READ | BT_GATT_PERM_WRITE, + read_tx_power, write_tx_power, NULL), + /* Advertised TX Power: Must be unlocked for both read and write. */ BT_GATT_CHARACTERISTIC(&eds_adv_tx_uuid.uuid, - BT_GATT_CHRC_READ | BT_GATT_CHRC_WRITE), - /* Must be unlocked for both read and write. */ - BT_GATT_DESCRIPTOR(&eds_adv_tx_uuid.uuid, - BT_GATT_PERM_READ | BT_GATT_PERM_WRITE, - read_adv_tx_power, write_adv_tx_power, NULL), - /* Lock State */ - BT_GATT_CHARACTERISTIC(&eds_lock_uuid.uuid, - BT_GATT_CHRC_READ | BT_GATT_CHRC_WRITE), - /* Readable in locked or unlocked state. + BT_GATT_CHRC_READ | BT_GATT_CHRC_WRITE, + BT_GATT_PERM_READ | BT_GATT_PERM_WRITE, + read_adv_tx_power, write_adv_tx_power, NULL), + /* Lock State: + * Readable in locked or unlocked state. * Writeable only in unlocked state. */ - BT_GATT_DESCRIPTOR(&eds_lock_uuid.uuid, - BT_GATT_PERM_READ | BT_GATT_PERM_WRITE, - read_lock, write_lock, NULL), - /* Unlock */ - BT_GATT_CHARACTERISTIC(&eds_unlock_uuid.uuid, - BT_GATT_CHRC_READ | BT_GATT_CHRC_WRITE), - /* Readable only in locked state. + BT_GATT_CHARACTERISTIC(&eds_lock_uuid.uuid, + BT_GATT_CHRC_READ | BT_GATT_CHRC_WRITE, + BT_GATT_PERM_READ | BT_GATT_PERM_WRITE, + read_lock, write_lock, NULL), + /* Unlock: + * Readable only in locked state. * Writeable only in locked state. */ - BT_GATT_DESCRIPTOR(&eds_unlock_uuid.uuid, - BT_GATT_PERM_READ | BT_GATT_PERM_WRITE, - read_unlock, write_unlock, NULL), - /* Public ECDH Key */ - BT_GATT_CHARACTERISTIC(&eds_ecdh_uuid.uuid, BT_GATT_CHRC_READ), - /* Readable only in unlocked state. Never writable. */ - BT_GATT_DESCRIPTOR(&eds_ecdh_uuid.uuid, BT_GATT_PERM_READ, - read_ecdh, NULL, &eds_ecdh), - /* EID Identity Key */ - BT_GATT_CHARACTERISTIC(&eds_eid_uuid.uuid, BT_GATT_CHRC_READ), - /* Readable only in unlocked state. Never writable. */ - BT_GATT_DESCRIPTOR(&eds_eid_uuid.uuid, BT_GATT_PERM_READ, - read_eid, NULL, eds_eid), - /* ADV Slot Data */ + BT_GATT_CHARACTERISTIC(&eds_unlock_uuid.uuid, + BT_GATT_CHRC_READ | BT_GATT_CHRC_WRITE, + BT_GATT_PERM_READ | BT_GATT_PERM_WRITE, + read_unlock, write_unlock, NULL), + /* Public ECDH Key: Readable only in unlocked state. Never writable. */ + BT_GATT_CHARACTERISTIC(&eds_ecdh_uuid.uuid, BT_GATT_CHRC_READ, + BT_GATT_PERM_READ, read_ecdh, NULL, &eds_ecdh), + /* EID Identity Key:Readable only in unlocked state. Never writable. */ + BT_GATT_CHARACTERISTIC(&eds_eid_uuid.uuid, BT_GATT_CHRC_READ, + BT_GATT_PERM_READ, read_eid, NULL, eds_eid), + /* ADV Slot Data: Must be unlocked for both read and write. */ BT_GATT_CHARACTERISTIC(&eds_data_uuid.uuid, - BT_GATT_CHRC_READ | BT_GATT_CHRC_WRITE), - /* Must be unlocked for both read and write. */ - BT_GATT_DESCRIPTOR(&eds_eid_uuid.uuid, - BT_GATT_PERM_READ | BT_GATT_PERM_WRITE, - read_adv_data, write_adv_data, NULL), - /* ADV Factory Reset */ - BT_GATT_CHARACTERISTIC(&eds_reset_uuid.uuid, BT_GATT_CHRC_WRITE), - /* Must be unlocked write. */ - BT_GATT_DESCRIPTOR(&eds_reset_uuid.uuid, - BT_GATT_PERM_READ | BT_GATT_PERM_WRITE, - NULL, write_reset, NULL), - /* ADV Remain Connectable */ + BT_GATT_CHRC_READ | BT_GATT_CHRC_WRITE, + BT_GATT_PERM_READ | BT_GATT_PERM_WRITE, + read_adv_data, write_adv_data, NULL), + /* ADV Factory Reset: Must be unlocked for write. */ + BT_GATT_CHARACTERISTIC(&eds_reset_uuid.uuid, BT_GATT_CHRC_WRITE, + BT_GATT_PERM_WRITE, NULL, write_reset, NULL), + /* ADV Remain Connectable: Must be unlocked for write. */ BT_GATT_CHARACTERISTIC(&eds_connectable_uuid.uuid, - BT_GATT_CHRC_READ | BT_GATT_CHRC_WRITE), - /* Must be unlocked for write. */ - BT_GATT_DESCRIPTOR(&eds_connectable_uuid.uuid, - BT_GATT_PERM_READ | BT_GATT_PERM_WRITE, - read_connectable, write_connectable, NULL), + BT_GATT_CHRC_READ | BT_GATT_CHRC_WRITE, + BT_GATT_PERM_READ | BT_GATT_PERM_WRITE, + read_connectable, write_connectable, NULL), }; static struct bt_gatt_service eds_svc = BT_GATT_SERVICE(eds_attrs); diff --git a/samples/bluetooth/gatt/bas.c b/samples/bluetooth/gatt/bas.c index 06c87eebe70..e127de9f159 100644 --- a/samples/bluetooth/gatt/bas.c +++ b/samples/bluetooth/gatt/bas.c @@ -45,9 +45,8 @@ static ssize_t read_blvl(struct bt_conn *conn, const struct bt_gatt_attr *attr, static struct bt_gatt_attr attrs[] = { BT_GATT_PRIMARY_SERVICE(BT_UUID_BAS), BT_GATT_CHARACTERISTIC(BT_UUID_BAS_BATTERY_LEVEL, - BT_GATT_CHRC_READ | BT_GATT_CHRC_NOTIFY), - BT_GATT_DESCRIPTOR(BT_UUID_BAS_BATTERY_LEVEL, BT_GATT_PERM_READ, - read_blvl, NULL, &battery), + BT_GATT_CHRC_READ | BT_GATT_CHRC_NOTIFY, + BT_GATT_PERM_READ, read_blvl, NULL, &battery), BT_GATT_CCC(blvl_ccc_cfg, blvl_ccc_cfg_changed), }; diff --git a/samples/bluetooth/gatt/cts.c b/samples/bluetooth/gatt/cts.c index d9ceda81588..eb16cb33e62 100644 --- a/samples/bluetooth/gatt/cts.c +++ b/samples/bluetooth/gatt/cts.c @@ -60,10 +60,9 @@ static ssize_t write_ct(struct bt_conn *conn, const struct bt_gatt_attr *attr, static struct bt_gatt_attr attrs[] = { BT_GATT_PRIMARY_SERVICE(BT_UUID_CTS), BT_GATT_CHARACTERISTIC(BT_UUID_CTS_CURRENT_TIME, BT_GATT_CHRC_READ | - BT_GATT_CHRC_NOTIFY | BT_GATT_CHRC_WRITE), - BT_GATT_DESCRIPTOR(BT_UUID_CTS_CURRENT_TIME, - BT_GATT_PERM_READ | BT_GATT_PERM_WRITE, - read_ct, write_ct, ct), + BT_GATT_CHRC_NOTIFY | BT_GATT_CHRC_WRITE, + BT_GATT_PERM_READ | BT_GATT_PERM_WRITE, + read_ct, write_ct, ct), BT_GATT_CCC(ct_ccc_cfg, ct_ccc_cfg_changed), }; diff --git a/samples/bluetooth/gatt/dis.c b/samples/bluetooth/gatt/dis.c index d74259cc32e..97f8481c4d2 100644 --- a/samples/bluetooth/gatt/dis.c +++ b/samples/bluetooth/gatt/dis.c @@ -44,13 +44,11 @@ static ssize_t read_manuf(struct bt_conn *conn, /* Device Information Service Declaration */ static struct bt_gatt_attr attrs[] = { BT_GATT_PRIMARY_SERVICE(BT_UUID_DIS), - BT_GATT_CHARACTERISTIC(BT_UUID_DIS_MODEL_NUMBER, BT_GATT_CHRC_READ), - BT_GATT_DESCRIPTOR(BT_UUID_DIS_MODEL_NUMBER, BT_GATT_PERM_READ, - read_model, NULL, NULL), + BT_GATT_CHARACTERISTIC(BT_UUID_DIS_MODEL_NUMBER, BT_GATT_CHRC_READ, + BT_GATT_PERM_READ, read_model, NULL, NULL), BT_GATT_CHARACTERISTIC(BT_UUID_DIS_MANUFACTURER_NAME, - BT_GATT_CHRC_READ), - BT_GATT_DESCRIPTOR(BT_UUID_DIS_MANUFACTURER_NAME, BT_GATT_PERM_READ, - read_manuf, NULL, NULL), + BT_GATT_CHRC_READ, BT_GATT_PERM_READ, + read_manuf, NULL, NULL), }; static struct bt_gatt_service dis_svc = BT_GATT_SERVICE(attrs); diff --git a/samples/bluetooth/gatt/hog.c b/samples/bluetooth/gatt/hog.c index 122106da814..5b3f8c9d158 100644 --- a/samples/bluetooth/gatt/hog.c +++ b/samples/bluetooth/gatt/hog.c @@ -143,23 +143,21 @@ static ssize_t write_ctrl_point(struct bt_conn *conn, /* HID Service Declaration */ static struct bt_gatt_attr attrs[] = { BT_GATT_PRIMARY_SERVICE(BT_UUID_HIDS), - BT_GATT_CHARACTERISTIC(BT_UUID_HIDS_INFO, BT_GATT_CHRC_READ), - BT_GATT_DESCRIPTOR(BT_UUID_HIDS_INFO, BT_GATT_PERM_READ, - read_info, NULL, &info), - BT_GATT_CHARACTERISTIC(BT_UUID_HIDS_REPORT_MAP, BT_GATT_CHRC_READ), - BT_GATT_DESCRIPTOR(BT_UUID_HIDS_REPORT_MAP, BT_GATT_PERM_READ, - read_report_map, NULL, NULL), + BT_GATT_CHARACTERISTIC(BT_UUID_HIDS_INFO, BT_GATT_CHRC_READ, + BT_GATT_PERM_READ, read_info, NULL, &info), + BT_GATT_CHARACTERISTIC(BT_UUID_HIDS_REPORT_MAP, BT_GATT_CHRC_READ, + BT_GATT_PERM_READ, read_report_map, NULL, NULL), BT_GATT_CHARACTERISTIC(BT_UUID_HIDS_REPORT, - BT_GATT_CHRC_READ | BT_GATT_CHRC_NOTIFY), - BT_GATT_DESCRIPTOR(BT_UUID_HIDS_REPORT, BT_GATT_PERM_READ_AUTHEN, - read_input_report, NULL, NULL), + BT_GATT_CHRC_READ | BT_GATT_CHRC_NOTIFY, + BT_GATT_PERM_READ_AUTHEN, + read_input_report, NULL, NULL), BT_GATT_CCC(input_ccc_cfg, input_ccc_changed), BT_GATT_DESCRIPTOR(BT_UUID_HIDS_REPORT_REF, BT_GATT_PERM_READ, read_report, NULL, &input), BT_GATT_CHARACTERISTIC(BT_UUID_HIDS_CTRL_POINT, - BT_GATT_CHRC_WRITE_WITHOUT_RESP), - BT_GATT_DESCRIPTOR(BT_UUID_HIDS_CTRL_POINT, BT_GATT_PERM_WRITE, - NULL, write_ctrl_point, &ctrl_point), + BT_GATT_CHRC_WRITE_WITHOUT_RESP, + BT_GATT_PERM_WRITE, + NULL, write_ctrl_point, &ctrl_point), }; static struct bt_gatt_service hog_svc = BT_GATT_SERVICE(attrs); diff --git a/samples/bluetooth/gatt/hrs.c b/samples/bluetooth/gatt/hrs.c index 08ce43b43d0..bff8fe18c8d 100644 --- a/samples/bluetooth/gatt/hrs.c +++ b/samples/bluetooth/gatt/hrs.c @@ -43,17 +43,13 @@ static ssize_t read_blsc(struct bt_conn *conn, const struct bt_gatt_attr *attr, /* Heart Rate Service Declaration */ static struct bt_gatt_attr attrs[] = { BT_GATT_PRIMARY_SERVICE(BT_UUID_HRS), - BT_GATT_CHARACTERISTIC(BT_UUID_HRS_MEASUREMENT, BT_GATT_CHRC_NOTIFY), - BT_GATT_DESCRIPTOR(BT_UUID_HRS_MEASUREMENT, BT_GATT_PERM_READ, NULL, - NULL, NULL), + BT_GATT_CHARACTERISTIC(BT_UUID_HRS_MEASUREMENT, BT_GATT_CHRC_NOTIFY, + BT_GATT_PERM_NONE, NULL, NULL, NULL), BT_GATT_CCC(hrmc_ccc_cfg, hrmc_ccc_cfg_changed), - BT_GATT_CHARACTERISTIC(BT_UUID_HRS_BODY_SENSOR, BT_GATT_CHRC_READ), - BT_GATT_DESCRIPTOR(BT_UUID_HRS_BODY_SENSOR, BT_GATT_PERM_READ, - read_blsc, NULL, NULL), - BT_GATT_CHARACTERISTIC(BT_UUID_HRS_CONTROL_POINT, BT_GATT_CHRC_WRITE), - /* TODO: Add write permission and callback */ - BT_GATT_DESCRIPTOR(BT_UUID_HRS_CONTROL_POINT, BT_GATT_PERM_READ, NULL, - NULL, NULL), + BT_GATT_CHARACTERISTIC(BT_UUID_HRS_BODY_SENSOR, BT_GATT_CHRC_READ, + BT_GATT_PERM_READ, read_blsc, NULL, NULL), + BT_GATT_CHARACTERISTIC(BT_UUID_HRS_CONTROL_POINT, BT_GATT_CHRC_WRITE, + BT_GATT_PERM_NONE, NULL, NULL, NULL), }; static struct bt_gatt_service hrs_svc = BT_GATT_SERVICE(attrs); diff --git a/samples/bluetooth/peripheral/src/main.c b/samples/bluetooth/peripheral/src/main.c index bf8d3c5187a..d75a2a832c5 100644 --- a/samples/bluetooth/peripheral/src/main.c +++ b/samples/bluetooth/peripheral/src/main.c @@ -169,30 +169,26 @@ static struct bt_gatt_attr vnd_attrs[] = { BT_GATT_PRIMARY_SERVICE(&vnd_uuid), BT_GATT_CHARACTERISTIC(&vnd_enc_uuid.uuid, BT_GATT_CHRC_READ | BT_GATT_CHRC_WRITE | - BT_GATT_CHRC_INDICATE), - BT_GATT_DESCRIPTOR(&vnd_enc_uuid.uuid, - BT_GATT_PERM_READ_ENCRYPT | - BT_GATT_PERM_WRITE_ENCRYPT, - read_vnd, write_vnd, vnd_value), + BT_GATT_CHRC_INDICATE, + BT_GATT_PERM_READ_ENCRYPT | + BT_GATT_PERM_WRITE_ENCRYPT, + read_vnd, write_vnd, vnd_value), BT_GATT_CCC(vnd_ccc_cfg, vnd_ccc_cfg_changed), BT_GATT_CHARACTERISTIC(&vnd_auth_uuid.uuid, - BT_GATT_CHRC_READ | BT_GATT_CHRC_WRITE), - BT_GATT_DESCRIPTOR(&vnd_auth_uuid.uuid, - BT_GATT_PERM_READ_AUTHEN | - BT_GATT_PERM_WRITE_AUTHEN, - read_vnd, write_vnd, vnd_value), + BT_GATT_CHRC_READ | BT_GATT_CHRC_WRITE, + BT_GATT_PERM_READ_AUTHEN | + BT_GATT_PERM_WRITE_AUTHEN, + read_vnd, write_vnd, vnd_value), BT_GATT_CHARACTERISTIC(&vnd_long_uuid.uuid, BT_GATT_CHRC_READ | - BT_GATT_CHRC_WRITE | BT_GATT_CHRC_EXT_PROP), - BT_GATT_DESCRIPTOR(&vnd_long_uuid.uuid, - BT_GATT_PERM_READ | BT_GATT_PERM_WRITE | - BT_GATT_PERM_PREPARE_WRITE, - read_long_vnd, write_long_vnd, &vnd_long_value), + BT_GATT_CHRC_WRITE | BT_GATT_CHRC_EXT_PROP, + BT_GATT_PERM_READ | BT_GATT_PERM_WRITE | + BT_GATT_PERM_PREPARE_WRITE, + read_long_vnd, write_long_vnd, &vnd_long_value), BT_GATT_CEP(&vnd_long_cep), BT_GATT_CHARACTERISTIC(&vnd_signed_uuid.uuid, BT_GATT_CHRC_READ | - BT_GATT_CHRC_WRITE | BT_GATT_CHRC_AUTH), - BT_GATT_DESCRIPTOR(&vnd_signed_uuid.uuid, - BT_GATT_PERM_READ | BT_GATT_PERM_WRITE, - read_signed, write_signed, &signed_value), + BT_GATT_CHRC_WRITE | BT_GATT_CHRC_AUTH, + BT_GATT_PERM_READ | BT_GATT_PERM_WRITE, + read_signed, write_signed, &signed_value), }; static struct bt_gatt_service vnd_svc = BT_GATT_SERVICE(vnd_attrs); diff --git a/samples/bluetooth/peripheral_csc/src/main.c b/samples/bluetooth/peripheral_csc/src/main.c index 2d748816b24..c27f7443c24 100644 --- a/samples/bluetooth/peripheral_csc/src/main.c +++ b/samples/bluetooth/peripheral_csc/src/main.c @@ -206,19 +206,18 @@ static ssize_t write_ctrl_point(struct bt_conn *conn, static struct bt_gatt_attr csc_attrs[] = { BT_GATT_PRIMARY_SERVICE(BT_UUID_CSC), - BT_GATT_CHARACTERISTIC(BT_UUID_CSC_MEASUREMENT, BT_GATT_CHRC_NOTIFY), - BT_GATT_DESCRIPTOR(BT_UUID_CSC_MEASUREMENT, 0x00, NULL, NULL, NULL), + BT_GATT_CHARACTERISTIC(BT_UUID_CSC_MEASUREMENT, BT_GATT_CHRC_NOTIFY, + 0x00, NULL, NULL, NULL), BT_GATT_CCC(csc_meas_ccc_cfg, csc_meas_ccc_cfg_changed), - BT_GATT_CHARACTERISTIC(BT_UUID_SENSOR_LOCATION, BT_GATT_CHRC_READ), - BT_GATT_DESCRIPTOR(BT_UUID_SENSOR_LOCATION, BT_GATT_PERM_READ, - read_location, NULL, &sensor_location), - BT_GATT_CHARACTERISTIC(BT_UUID_CSC_FEATURE, BT_GATT_CHRC_READ), - BT_GATT_DESCRIPTOR(BT_UUID_CSC_FEATURE, BT_GATT_PERM_READ, - read_csc_feature, NULL, NULL), + BT_GATT_CHARACTERISTIC(BT_UUID_SENSOR_LOCATION, BT_GATT_CHRC_READ, + BT_GATT_PERM_READ, read_location, NULL, + &sensor_location), + BT_GATT_CHARACTERISTIC(BT_UUID_CSC_FEATURE, BT_GATT_CHRC_READ, + BT_GATT_PERM_READ, read_csc_feature, NULL, NULL), BT_GATT_CHARACTERISTIC(BT_UUID_SC_CONTROL_POINT, - BT_GATT_CHRC_WRITE | BT_GATT_CHRC_INDICATE), - BT_GATT_DESCRIPTOR(BT_UUID_SC_CONTROL_POINT, BT_GATT_PERM_WRITE, NULL, - write_ctrl_point, &sensor_location), + BT_GATT_CHRC_WRITE | BT_GATT_CHRC_INDICATE, + BT_GATT_PERM_WRITE, NULL, write_ctrl_point, + &sensor_location), BT_GATT_CCC(ctrl_point_ccc_cfg, ctrl_point_ccc_cfg_changed), }; diff --git a/samples/bluetooth/peripheral_esp/src/main.c b/samples/bluetooth/peripheral_esp/src/main.c index 681cf9f88ec..89daddfbaf4 100644 --- a/samples/bluetooth/peripheral_esp/src/main.c +++ b/samples/bluetooth/peripheral_esp/src/main.c @@ -292,9 +292,9 @@ static struct bt_gatt_attr ess_attrs[] = { /* Temperature Sensor 1 */ BT_GATT_CHARACTERISTIC(BT_UUID_TEMPERATURE, - BT_GATT_CHRC_READ | BT_GATT_CHRC_NOTIFY), - BT_GATT_DESCRIPTOR(BT_UUID_TEMPERATURE, BT_GATT_PERM_READ, - read_u16, NULL, &sensor_1.temp_value), + BT_GATT_CHRC_READ | BT_GATT_CHRC_NOTIFY, + BT_GATT_PERM_READ, + read_u16, NULL, &sensor_1.temp_value), BT_GATT_DESCRIPTOR(BT_UUID_ES_MEASUREMENT, BT_GATT_PERM_READ, read_es_measurement, NULL, &sensor_1.meas), BT_GATT_CUD(SENSOR_1_NAME, BT_GATT_PERM_READ), @@ -307,9 +307,9 @@ static struct bt_gatt_attr ess_attrs[] = { /* Temperature Sensor 2 */ BT_GATT_CHARACTERISTIC(BT_UUID_TEMPERATURE, - BT_GATT_CHRC_READ | BT_GATT_CHRC_NOTIFY), - BT_GATT_DESCRIPTOR(BT_UUID_TEMPERATURE, BT_GATT_PERM_READ, - read_u16, NULL, &sensor_2.temp_value), + BT_GATT_CHRC_READ | BT_GATT_CHRC_NOTIFY, + BT_GATT_PERM_READ, + read_u16, NULL, &sensor_2.temp_value), BT_GATT_DESCRIPTOR(BT_UUID_ES_MEASUREMENT, BT_GATT_PERM_READ, read_es_measurement, NULL, &sensor_2.meas), BT_GATT_CUD(SENSOR_2_NAME, BT_GATT_PERM_READ), @@ -321,9 +321,9 @@ static struct bt_gatt_attr ess_attrs[] = { BT_GATT_CCC(sensor_2.ccc_cfg, temp_ccc_cfg_changed), /* Humidity Sensor */ - BT_GATT_CHARACTERISTIC(BT_UUID_HUMIDITY, BT_GATT_CHRC_READ), - BT_GATT_DESCRIPTOR(BT_UUID_HUMIDITY, BT_GATT_PERM_READ, - read_u16, NULL, &sensor_3.humid_value), + BT_GATT_CHARACTERISTIC(BT_UUID_HUMIDITY, BT_GATT_CHRC_READ, + BT_GATT_PERM_READ, + read_u16, NULL, &sensor_3.humid_value), BT_GATT_CUD(SENSOR_3_NAME, BT_GATT_PERM_READ), BT_GATT_DESCRIPTOR(BT_UUID_ES_MEASUREMENT, BT_GATT_PERM_READ, read_es_measurement, NULL, &sensor_3.meas), diff --git a/samples/boards/arduino_101/environmental_sensing/ap/src/main.c b/samples/boards/arduino_101/environmental_sensing/ap/src/main.c index 14c50822ade..1d745f39a8d 100644 --- a/samples/boards/arduino_101/environmental_sensing/ap/src/main.c +++ b/samples/boards/arduino_101/environmental_sensing/ap/src/main.c @@ -51,19 +51,18 @@ static ssize_t read_u32(struct bt_conn *conn, const struct bt_gatt_attr *attr, static struct bt_gatt_attr attrs[] = { BT_GATT_PRIMARY_SERVICE(BT_UUID_ESS), - BT_GATT_CHARACTERISTIC(BT_UUID_TEMPERATURE, BT_GATT_CHRC_READ), - BT_GATT_DESCRIPTOR(BT_UUID_TEMPERATURE, BT_GATT_PERM_READ, - read_u16, NULL, &temp_value), + BT_GATT_CHARACTERISTIC(BT_UUID_TEMPERATURE, BT_GATT_CHRC_READ, + BT_GATT_PERM_READ, read_u16, NULL, &temp_value), BT_GATT_CUD(TEMPERATURE_CUD, BT_GATT_PERM_READ), - BT_GATT_CHARACTERISTIC(BT_UUID_HUMIDITY, BT_GATT_CHRC_READ), - BT_GATT_DESCRIPTOR(BT_UUID_HUMIDITY, BT_GATT_PERM_READ, - read_u16, NULL, &humidity_value), + BT_GATT_CHARACTERISTIC(BT_UUID_HUMIDITY, BT_GATT_CHRC_READ, + BT_GATT_PERM_READ, read_u16, NULL, + &humidity_value), BT_GATT_CUD(HUMIDITY_CUD, BT_GATT_PERM_READ), - BT_GATT_CHARACTERISTIC(BT_UUID_PRESSURE, BT_GATT_CHRC_READ), - BT_GATT_DESCRIPTOR(BT_UUID_PRESSURE, BT_GATT_PERM_READ, - read_u32, NULL, &pressure_value), + BT_GATT_CHARACTERISTIC(BT_UUID_PRESSURE, BT_GATT_CHRC_READ, + BT_GATT_PERM_READ, read_u32, NULL, + &pressure_value), BT_GATT_CUD(PRESSURE_CUD, BT_GATT_PERM_READ), }; diff --git a/samples/boards/microbit/pong/src/ble.c b/samples/boards/microbit/pong/src/ble.c index aa50b59a0ea..9d8295b26ee 100644 --- a/samples/boards/microbit/pong/src/ble.c +++ b/samples/boards/microbit/pong/src/ble.c @@ -519,9 +519,8 @@ static void pong_ccc_cfg_changed(const struct bt_gatt_attr *attr, u16_t val) static struct bt_gatt_attr pong_attrs[] = { /* Vendor Primary Service Declaration */ BT_GATT_PRIMARY_SERVICE(&pong_svc_uuid.uuid), - BT_GATT_CHARACTERISTIC(&pong_chr_uuid.uuid, BT_GATT_CHRC_NOTIFY), - BT_GATT_DESCRIPTOR(&pong_chr_uuid.uuid, BT_GATT_PERM_NONE, - NULL, NULL, NULL), + BT_GATT_CHARACTERISTIC(&pong_chr_uuid.uuid, BT_GATT_CHRC_NOTIFY, + BT_GATT_PERM_NONE, NULL, NULL, NULL), BT_GATT_CCC(pong_ccc_cfg, pong_ccc_cfg_changed), }; diff --git a/subsys/bluetooth/host/gatt.c b/subsys/bluetooth/host/gatt.c index e14b511d1f3..f0ea96bb77f 100644 --- a/subsys/bluetooth/host/gatt.c +++ b/subsys/bluetooth/host/gatt.c @@ -70,12 +70,10 @@ static ssize_t read_appearance(struct bt_conn *conn, static struct bt_gatt_attr gap_attrs[] = { BT_GATT_PRIMARY_SERVICE(BT_UUID_GAP), - BT_GATT_CHARACTERISTIC(BT_UUID_GAP_DEVICE_NAME, BT_GATT_CHRC_READ), - BT_GATT_DESCRIPTOR(BT_UUID_GAP_DEVICE_NAME, BT_GATT_PERM_READ, - read_name, NULL, NULL), - BT_GATT_CHARACTERISTIC(BT_UUID_GAP_APPEARANCE, BT_GATT_CHRC_READ), - BT_GATT_DESCRIPTOR(BT_UUID_GAP_APPEARANCE, BT_GATT_PERM_READ, - read_appearance, NULL, NULL), + BT_GATT_CHARACTERISTIC(BT_UUID_GAP_DEVICE_NAME, BT_GATT_CHRC_READ, + BT_GATT_PERM_READ, read_name, NULL, NULL), + BT_GATT_CHARACTERISTIC(BT_UUID_GAP_APPEARANCE, BT_GATT_CHRC_READ, + BT_GATT_PERM_READ, read_appearance, NULL, NULL), }; static struct bt_gatt_service gap_svc = BT_GATT_SERVICE(gap_attrs); @@ -90,9 +88,8 @@ static void sc_ccc_cfg_changed(const struct bt_gatt_attr *attr, static struct bt_gatt_attr gatt_attrs[] = { BT_GATT_PRIMARY_SERVICE(BT_UUID_GATT), - BT_GATT_CHARACTERISTIC(BT_UUID_GATT_SC, BT_GATT_CHRC_INDICATE), - BT_GATT_DESCRIPTOR(BT_UUID_GATT_SC, BT_GATT_PERM_NONE, - NULL, NULL, NULL), + BT_GATT_CHARACTERISTIC(BT_UUID_GATT_SC, BT_GATT_CHRC_INDICATE, + BT_GATT_PERM_NONE, NULL, NULL, NULL), BT_GATT_CCC(sc_ccc_cfg, sc_ccc_cfg_changed), }; @@ -1351,6 +1348,12 @@ done: return 0; } +#define BT_GATT_CHRC(_uuid, _props) \ + BT_GATT_ATTRIBUTE(BT_UUID_GATT_CHRC, BT_GATT_PERM_READ, \ + bt_gatt_attr_read_chrc, NULL, \ + (&(struct bt_gatt_chrc) { .uuid = _uuid, \ + .properties = _props, })) + static u16_t parse_characteristic(struct bt_conn *conn, const void *pdu, struct bt_gatt_discover_params *params, u16_t length) @@ -1406,8 +1409,8 @@ static u16_t parse_characteristic(struct bt_conn *conn, const void *pdu, continue; } - attr = (&(struct bt_gatt_attr)BT_GATT_CHARACTERISTIC(&u.uuid, - chrc->properties)); + attr = (&(struct bt_gatt_attr)BT_GATT_CHRC(&u.uuid, + chrc->properties)); attr->handle = handle; if (params->func(conn, attr, params) == BT_GATT_ITER_STOP) { diff --git a/subsys/bluetooth/host/mesh/proxy.c b/subsys/bluetooth/host/mesh/proxy.c index c96e3b0c3f6..5f2e02c1fa7 100644 --- a/subsys/bluetooth/host/mesh/proxy.c +++ b/subsys/bluetooth/host/mesh/proxy.c @@ -631,14 +631,13 @@ static struct bt_gatt_attr prov_attrs[] = { BT_GATT_PRIMARY_SERVICE(BT_UUID_MESH_PROV), BT_GATT_CHARACTERISTIC(BT_UUID_MESH_PROV_DATA_IN, - BT_GATT_CHRC_WRITE_WITHOUT_RESP), - BT_GATT_DESCRIPTOR(BT_UUID_MESH_PROV_DATA_IN, BT_GATT_PERM_WRITE, - NULL, proxy_recv, (void *)1), + BT_GATT_CHRC_WRITE_WITHOUT_RESP, + BT_GATT_PERM_WRITE, NULL, proxy_recv, + (void *)1), BT_GATT_CHARACTERISTIC(BT_UUID_MESH_PROV_DATA_OUT, - BT_GATT_CHRC_NOTIFY), - BT_GATT_DESCRIPTOR(BT_UUID_MESH_PROV_DATA_OUT, BT_GATT_PERM_NONE, - NULL, NULL, NULL), + BT_GATT_CHRC_NOTIFY, BT_GATT_PERM_NONE, + NULL, NULL, NULL), /* Add custom CCC as clients need to be tracked individually */ BT_GATT_DESCRIPTOR(BT_UUID_GATT_CCC, BT_GATT_PERM_WRITE | BT_GATT_PERM_READ, @@ -738,14 +737,14 @@ static struct bt_gatt_attr proxy_attrs[] = { BT_GATT_PRIMARY_SERVICE(BT_UUID_MESH_PROXY), BT_GATT_CHARACTERISTIC(BT_UUID_MESH_PROXY_DATA_IN, - BT_GATT_CHRC_WRITE_WITHOUT_RESP), - BT_GATT_DESCRIPTOR(BT_UUID_MESH_PROXY_DATA_IN, BT_GATT_PERM_WRITE, - NULL, proxy_recv, NULL), + BT_GATT_CHRC_WRITE_WITHOUT_RESP, + BT_GATT_PERM_WRITE, + NULL, proxy_recv, NULL), BT_GATT_CHARACTERISTIC(BT_UUID_MESH_PROXY_DATA_OUT, - BT_GATT_CHRC_NOTIFY), - BT_GATT_DESCRIPTOR(BT_UUID_MESH_PROXY_DATA_OUT, BT_GATT_PERM_NONE, - NULL, NULL, NULL), + BT_GATT_CHRC_NOTIFY, + BT_GATT_PERM_NONE, + NULL, NULL, NULL), /* Add custom CCC as clients need to be tracked individually */ BT_GATT_DESCRIPTOR(BT_UUID_GATT_CCC, BT_GATT_PERM_READ | BT_GATT_PERM_WRITE, diff --git a/subsys/bluetooth/shell/gatt.c b/subsys/bluetooth/shell/gatt.c index b35c0872c36..4a030aefffc 100644 --- a/subsys/bluetooth/shell/gatt.c +++ b/subsys/bluetooth/shell/gatt.c @@ -606,27 +606,24 @@ static struct bt_gatt_attr vnd_attrs[] = { BT_GATT_PRIMARY_SERVICE(&vnd_uuid), BT_GATT_CHARACTERISTIC(&vnd_auth_uuid.uuid, - BT_GATT_CHRC_READ | BT_GATT_CHRC_WRITE), - BT_GATT_DESCRIPTOR(&vnd_auth_uuid.uuid, - BT_GATT_PERM_READ_AUTHEN | - BT_GATT_PERM_WRITE_AUTHEN, - read_vnd, write_vnd, vnd_value), + BT_GATT_CHRC_READ | BT_GATT_CHRC_WRITE, + BT_GATT_PERM_READ_AUTHEN | + BT_GATT_PERM_WRITE_AUTHEN, + read_vnd, write_vnd, vnd_value), BT_GATT_CHARACTERISTIC(&vnd_long_uuid1.uuid, BT_GATT_CHRC_READ | - BT_GATT_CHRC_WRITE | BT_GATT_CHRC_EXT_PROP), - BT_GATT_DESCRIPTOR(&vnd_long_uuid1.uuid, - BT_GATT_PERM_READ | BT_GATT_PERM_WRITE | - BT_GATT_PERM_PREPARE_WRITE, - read_long_vnd, write_long_vnd, - &vnd_long_value1), + BT_GATT_CHRC_WRITE | BT_GATT_CHRC_EXT_PROP, + BT_GATT_PERM_READ | BT_GATT_PERM_WRITE | + BT_GATT_PERM_PREPARE_WRITE, + read_long_vnd, write_long_vnd, + &vnd_long_value1), BT_GATT_CHARACTERISTIC(&vnd_long_uuid2.uuid, BT_GATT_CHRC_READ | - BT_GATT_CHRC_WRITE | BT_GATT_CHRC_EXT_PROP), - BT_GATT_DESCRIPTOR(&vnd_long_uuid2.uuid, - BT_GATT_PERM_READ | BT_GATT_PERM_WRITE | - BT_GATT_PERM_PREPARE_WRITE, - read_long_vnd, write_long_vnd, - &vnd_long_value2), + BT_GATT_CHRC_WRITE | BT_GATT_CHRC_EXT_PROP, + BT_GATT_PERM_READ | BT_GATT_PERM_WRITE | + BT_GATT_PERM_PREPARE_WRITE, + read_long_vnd, write_long_vnd, + &vnd_long_value2), }; static struct bt_gatt_service vnd_svc = BT_GATT_SERVICE(vnd_attrs); @@ -637,9 +634,8 @@ static struct bt_gatt_attr vnd1_attrs[] = { BT_GATT_CHARACTERISTIC(&vnd1_echo_uuid.uuid, BT_GATT_CHRC_WRITE_WITHOUT_RESP | - BT_GATT_CHRC_NOTIFY), - BT_GATT_DESCRIPTOR(&vnd1_echo_uuid.uuid, - BT_GATT_PERM_WRITE, NULL, write_vnd1, NULL), + BT_GATT_CHRC_NOTIFY, + BT_GATT_PERM_WRITE, NULL, write_vnd1, NULL), BT_GATT_CCC(vnd1_ccc_cfg, vnd1_ccc_cfg_changed), }; @@ -730,10 +726,9 @@ static struct bt_gatt_attr met_attrs[] = { BT_GATT_PRIMARY_SERVICE(&met_svc_uuid), BT_GATT_CHARACTERISTIC(&met_char_uuid.uuid, - BT_GATT_CHRC_READ | BT_GATT_CHRC_WRITE), - BT_GATT_DESCRIPTOR(&met_char_uuid.uuid, - BT_GATT_PERM_READ | BT_GATT_PERM_WRITE, - read_met, write_met, met_char_value), + BT_GATT_CHRC_READ | BT_GATT_CHRC_WRITE, + BT_GATT_PERM_READ | BT_GATT_PERM_WRITE, + read_met, write_met, met_char_value), }; static struct bt_gatt_service met_svc = BT_GATT_SERVICE(met_attrs); diff --git a/tests/bluetooth/tester/src/gatt.c b/tests/bluetooth/tester/src/gatt.c index d63eb3b626a..9f50dbb5930 100644 --- a/tests/bluetooth/tester/src/gatt.c +++ b/tests/bluetooth/tester/src/gatt.c @@ -367,7 +367,10 @@ static int alloc_characteristic(struct add_characteristic *ch) /* Add Characteristic Declaration */ attr_chrc = gatt_db_add(&(struct bt_gatt_attr) - BT_GATT_CHARACTERISTIC(NULL, 0), + BT_GATT_ATTRIBUTE(BT_UUID_GATT_CHRC, + BT_GATT_PERM_READ, + bt_gatt_attr_read_chrc, NULL, + (&(struct bt_gatt_chrc){})), sizeof(*chrc_data)); if (!attr_chrc) { return -EINVAL; @@ -398,7 +401,7 @@ static int alloc_characteristic(struct add_characteristic *ch) /* Add Characteristic Value */ attr_value = gatt_db_add(&(struct bt_gatt_attr) - BT_GATT_DESCRIPTOR(ch->uuid, + BT_GATT_ATTRIBUTE(ch->uuid, ch->permissions & GATT_PERM_MASK, read_value, write_value, &value), sizeof(value));